
! script name: vpksheets.d/vpktorusaxis
! var_solids: construct torus along an axis line

!A
!A NAME:
!A
!A 	Torus: Axis Line	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will construct a torus along an axis line.
!A 	A torus is a circular tube.
!A
!B INSTRUCTIONS:
!B
!B 	AXIAL RADIUS: Enter the distance from
!B 		the center of the torus to the center of the tube.
!B
!B~ image location - images/ToriiRadii.gif
!B
!B 	RADIAL RADIUS: Enter the radius of the tube.
!B
!B 	STARTING AXIAL ANGLE: Enter the starting
!B 		angle of the torus.
!B
!B 	AXIAL ANGULAR EXTENT: Enter the number of
!B 		degrees and the direction ( + CCW, - CW ) from the
!B 		starting axial angle to the ending axial angle.
!B 		The axial angular extent determines the ending axial angle.
!B
!B 	STARTING RADIAL ANGLE: Enter the starting angle of
!B 		the tube.
!B
!B 	RADIAL ANGULAR EXTENT: Enter the number of
!B 		degrees and the direction ( + CCW, - CW ) from the
!B 		starting radial angle to the ending radial angle.
!B 		The radial angular extent determines the ending radial angle.
!B
!B 	PICK AXIS LINE: Pick the line to be used as
!B 		the axis of the torus.
!B

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

DIM Destination$[256]
DIM Answer$[256]
DIM Axial_var$[256]
DIM Radial_var$[256]
DIM Start_axial_var$[256]
DIM Axial_angle$[256]
DIM Start_radial_var$[256]
DIM Axial_radial$[256]
DIM Name$[256]
DIM Axis_line$[256]
DEG

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

ActivateUndo
Units= CurrentUnits
IF Units= WsMetric THEN
        R1= 100
        R2= 25
ELSE
        R1= 5
        R2= 1
END IF

Stat= GLPlotOn
Cloop:!
Stat=SetInputFormat("n4=","")
Stat=SetRadiusEquals(R1)
R1=InputRadius("AXIAL RADIUS")
IF ExitScript(Destination$) THEN Leave
No_axial_var= LastVariableInput(Axial_var$)
C1= LastPickEnt
IF ValidGeometry(C1) THEN
        IF NOT ValidDependency(C1) THEN Cloop
        No_axial_var=0
        Stat= EntityNameCheck(C1,Axial_var$)
END IF

Stat=SetInputFormat("n4=","")
Stat=SetRadiusEquals(R2)
R2=InputRadius("RADIAL RADIUS")
IF ExitScript(Destination$) THEN Leave
No_radial_var= LastVariableInput(Radial_var$)
C1= LastPickEnt
IF ValidGeometry(C1) THEN
        IF NOT ValidDependency(C1) THEN Cloop
        No_radial_var=0
        Stat= EntityNameCheck(C1,radial_var$)
END IF

Stat=SetAngleEquals(0)
Axial_astart=InputAngle("STARTING AXIAL ANGLE ( 0 90 180 270) ")
IF ExitScript(Destination$) THEN Leave
No_start_axial= LastVariableInput(Start_axial_var$)

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(360)
Axial_angle=GetValue("AXIAL ANGULAR EXTENT ( 90 180 360 ) ",Answer$)
IF ExitScript(Destination$) THEN Leave
No_axial_angle= LastVariableInput(Axial_angle$)

Stat=SetAngleEquals(0)
Radial_astart=InputAngle("STARTING RADIAL ANGLE ( 0 90 180 270) ")
IF ExitScript(Destination$) THEN Leave
No_start_radial= LastVariableInput(Start_radial_var$)

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(180)
Radial_angle=GetValue("RADIAL ANGULAR EXTENT ( 90 180 360 ) ",Answer$)
IF ExitScript(Destination$) THEN Leave
No_radial_angle= LastVariableInput(radial_angle$)




Pick_axis:!
Stat=SetInputFormat("n4","")
Axis_line=PickSpecificEnt("PICK AXIS LINE",WsPickLines)
IF ExitScript(Destination$) THEN Leave
IF NOT ValidGeometry(Axis_line) THEN Pick_axis
IF NOT ValidDependency(Axis_line) THEN Pick_axis
Stat= EntityNameCheck(Axis_line,Axis_line$)

T=LastPickPara
IF T<=0.5 THEN
        Direction= WsForward
ELSE
        Direction= WsReverse
END IF


WPKClearErrorFlag
Stat= GenerateVarName("Body",Name$)
RecordFunctionOn
Stat= RecordDescr("SHEET: Axis line torus")
IF No_axial_var THEN
        V1= FreeParameter("Axial Radius",R1)
ELSE
        V1= FreeParameter("Axial Radius",Axial_var$)
END IF
IF No_radial_var THEN
        V2= FreeParameter("Radial Radius",R2)
ELSE
        V2= FreeParameter("Radial Radius",Radial_var$)
END IF
IF No_start_axial THEN
        V3= FreeParameter("Axial start angle ",Axial_astart)
ELSE
        V3= FreeParameter("Axial start angle ",Start_axial_angle$)
END IF
IF No_axial_angle THEN
        V4= FreeParameter("Axial Angle",Axial_angle)
ELSE
        V4= FreeParameter("Axial Angle",Axial_angle$)
END IF
IF No_start_radial THEN
        V5= FreeParameter("Radial start angle ",Radial_astart)
ELSE
        V5= FreeParameter("Radial start angle ",Start_radial_angle$)
END IF
IF No_radial_angle THEN
        V6= FreeParameter("Radial Angle",Radial_angle)
ELSE
        V6= FreeParameter("Radial Angle",Radial_angle$)
END IF
C1=AxisLineTorus(Axis_line$,V1,V2,V3,V4,V5,V6,Direction)
RecordFunctionOff
IF ValidGeometry(C1) THEN
        Make_record= WsTrue
        RecordFunctionOn
        G1=WPKMakeBsurf(C1)
        Stat= WPKNameBodyGroup(G1,Name$)
        Stat= WPKSetBodyParent(G1,1)
        Stat= DeleteEntityList(G1,C1)
        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("toroidal sheet")
        Stat= AddItemToUndo(WsUBPKSessionMark)
        Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
        WPKErrorCheck
END IF
GOTO Cloop

Leave:!
Stat=SetInputFormat("n4","")
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END
