
! script name: vpksheets.d/vpkdisk
! var_solids: construct disk

!A
!A NAME:
!A
!A 	Disk: Define	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script constructs a disk ( or a part of a disk ), which is
!A 	a plane with a circular boundary.
!A
!A~ image location - images/disk.gif
!A
!B INSTRUCTIONS:
!B
!B 	DISK RADIUS: Enter the radius of the disk to be constructed.
!B
!B 	CENTER POINT ABS X,Y,Z: Enter the X,Y,Z coordinates of the center
!B 		point of the disk.  NOTE: See XYZ INPUT OPTIONS.
!B
!B 	ROTATION ANGLE: Enter the orientation angle of the axis of the disk
!B 		in the XY plane.
!B
!B 	X AXIS TILT ANGLE: This represents the angle of tilt of the axis of
!B 		the disk around the X axis.
!B
!B 	Y AXIS TILT ANGLE: This represents the angle of tilt of the axis of
!B 		the disk around the Y axis.
!B
!# see also - points.d/xyzinput.hlp

Stat=ChangeLabelStr("ScriptNameStatus","Function: disk ")

DIM Destination$[256]
DIM Answer$[256]
DIM Radius_var$[256]
DIM Name$[256]
DIM Center$[256]
DIM Xangle_var$[256]
DIM Yangle_var$[256]
DIM Zangle_var$[256]
DEG

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

ActivateUndo
Units= CurrentUnits
IF Units= WsMetric THEN
        Radius= 25
ELSE
        Radius= 1
END IF
Astart= 0
Angle= 360

Stat= GLPlotOn
Cloop:!
Stat=SetInputFormat("n4=","")
Stat=SetRadiusEquals(Radius)
Radius=InputRadius("DISK RADIUS")
IF ExitScript(Destination$) THEN Leave
No_radius_var= LastVariableInput(Radius_var$)
C1= LastPickEnt
IF ValidGeometry(C1) THEN
        IF NOT ValidDependency(C1) THEN Cloop
        No_radius_var=0
        Stat= EntityNameCheck(C1,Radius_var$)
END IF


Pick_point:Stat=SetInputFormat("n4=","")
Pc=XyzInput("CENTER POINT",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Pc) THEN Pick_point
E1= LastPickEnt
Pick_para= LastPickPara
Pick_return= CurrPickReturn
IF NOT ValidDependency(E1) THEN
        E1= CopyEntity(Pc)
        Stat= EntityNameCheck(E1,Center$)
        Pc_created= WsTrue
ELSE
        Stat= EntityNameCheck(E1,Center$)
        Pc_created= WsFalse
END IF
Stat=SetLastPoint(Pc)
Stat= DeleteEntity(Pc)

Stat=SetAngleEquals(0)
Zangle=InputAngle("ROTATION ANGLE ",WsSigned)
IF ExitScript(Destination$) THEN Leave
No_zangle_var= LastVariableInput(Zangle_var$)


Stat=SetAngleEquals(0)
Xangle=InputAngle("X AXIS TILT ANGLE ",WsSigned)
IF ExitScript(Destination$) THEN Leave
No_xangle_var= LastVariableInput(Xangle_var$)

Stat=SetAngleEquals(0)
Yangle=InputAngle("Y AXIS TILT ANGLE ",WsSigned)
IF ExitScript(Destination$) THEN Leave
No_yangle_var= LastVariableInput(Yangle_var$)


WPKClearErrorFlag
Stat= GenerateVarName("Body",Name$)
RecordFunctionOn
Stat= RecordDescr("SHEET: Disk")
SELECT Pick_return
CASE WsGeometryEnd
        Pc= ParameterReturnPt(Center$,Pick_para,WsGeometryEnd)
CASE WsGeometryMid
        Pc= ParameterReturnPt(Center$,Pick_para,WsGeometryMid)
CASE WsGeomCenter
        Pc= ParameterReturnPt(Center$,Pick_para,WsGeomCenter)
END SELECT
IF No_radius_var THEN
        V1= FreeParameter("Radius",Radius)
ELSE
        V1= FreeParameter("Radius",Radius_var$)
END IF
IF No_xangle_var THEN
        V4= FreeParameter("X Angle",Xangle)
ELSE
        V4= FreeParameter("X Angle",Xangle_var$)
END IF
IF No_yangle_var THEN
        V5= FreeParameter("Y Angle",Yangle)
ELSE
        V5= FreeParameter("Y Angle",Yangle_var$)
END IF
IF No_zangle_var THEN
        V6= FreeParameter("Z Angle",Zangle)
ELSE
        V6= FreeParameter("Z Angle",Zangle_var$)
END IF
Trans1=AngleTransform(Pc,V4,V5,V6,WsWorkplaneVals)
D1=Disk(Trans1,V1,0,360)
RecordFunctionOff
IF ValidGeometry(D1) THEN
        Make_record= WsTrue
        RecordFunctionOn
	Pkbody=WPKBasicSolid(D1)
        Stat= WPKNameBody(Pkbody,Name$)
        Stat= WPKSetBodyParent(Pkbody)
        Stat= DeleteEntity(D1)
        RecordFunctionOff
ELSE
        Make_record= WsFalse
END IF
RecordFunctionOn
Stat= DeleteEntity(Pc)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF Make_record= WsFalse THEN
        IF Pc_created THEN Stat= DeleteEntity(Center$)
        DelLastVarRecord
ELSE
        Stat= WPKSolidRecordOn(Curr_record)
        ActivateUndo
        Stat= AdvanceUndoNumber("disk sheet")
        IF Pc_created THEN Stat= AddItemToUndo(WsUBCreateMode,Center$)
        Stat= AddItemToUndo(WsUBPKSessionMark)
        Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
        WPKErrorCheck
END IF
GOTO Cloop

Leave:!
Stat=DeleteEntity(Pc)

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