
! script name: vsolids.d/torus
! var_topic: construct torus

!A
!A NAME:
!A
!A 	Torus: Define	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will construct a torus.  A torus is a circular tube.
!A
!A~ image location - images/Torus.gif
!A
!B INSTRUCTIONS:
!B
!B 	AXIAL RADIUS: Enter the distance from the center of the torus to the
!B 		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 angle of the torus.
!B
!B 	AXIAL ANGULAR EXTENT: Enter the number of degrees and the direction
!B 		( + CCW, - CW ) from the starting axial angle to the ending
!B 		axial angle.  The axial angular extent determines the ending 
!B 		axial angle.
!B
!B 	STARTING RADIAL ANGLE: Enter the starting angle of the tube.
!B
!B 	RADIAL ANGULAR EXTENT: Enter the number of degrees and the direction
!B 		( + CCW, - CW ) from the starting radial angle to the ending
!B 		radial angle.  The radial angular extent determines the ending
!B 		radial angle.
!B
!B 	CENTER POINT ABS X,Y,Z: Enter the X,Y,Z coordinates of the center of
!B 		the torus.  NOTE: See XYZ INPUT OPTIONS.
!B
!B 	ROTATION ANGLE: Enter the orientation angle of the axis of the torus
!B 		in the XY plane.
!B
!B 	X AXIS TILT ANGLE: This represents the angle of tilt of the axis of
!B 		the torus around the X axis.
!B
!B 	Y AXIS TILT ANGLE: This represents the angle of tilt of the axis of
!B 		the torus around the Y axis.
!B
!C NOTES:
!C
!C 	The U contours of a torus are the axial circles and the V contours
!C 	are the radial circles.
!C
!# see also - points.d/xyzinput.hlp

Stat=ChangeLabelStr("ScriptNameStatus","Function: 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 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
        R1= 100
        R2= 25
ELSE
        R1= 5
        R2= 1
END IF

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_point:Stat=SetInputFormat("n4=","")
E1=PickEntity("CENTER POINT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(E1) THEN Pick_point
IF NOT ValidDependency(E1) THEN Pick_point
T= LastPickPara
Pick_return= CurrPickReturn
Stat= EntityNameCheck(E1,Center$)
Pc= ParameterReturnPt(E1,T,Pick_return)
Stat=SetEqualsValue(Radius)
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$)

Stat=DeleteEntity(Pt)

Stat= GenerateVarName(WsTorusSolidEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("TORUS: Define")
Stat= SetRecDelLastExec
SELECT Pick_return
CASE WsGeometryEnd
        Pc= ParameterReturnPt(Center$,T,WsGeometryEnd)
CASE WsGeometryMid
        Pc= ParameterReturnPt(Center$,T,WsGeometryMid)
CASE WsGeomCenter
        Pc= ParameterReturnPt(Center$,T,WsGeomCenter)
END SELECT
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
IF No_xangle_var THEN
        V7= FreeParameter("X Angle",Xangle)
ELSE
        V7= FreeParameter("X Angle",Xangle_var$)
END IF
IF No_yangle_var THEN
        V8= FreeParameter("Y Angle",Yangle)
ELSE
        V8= FreeParameter("Y Angle",Yangle_var$)
END IF
IF No_zangle_var THEN
        V9= FreeParameter("Z Angle",Zangle)
ELSE
        V9= FreeParameter("Z Angle",Zangle_var$)
END IF
Trans1=AngleTransform(Pc,V7,V8,V9,WsWorkplaneVals)
C1=Torus(Trans1,V1,V2,V3,V4,V5,V6)
Stat= NameEntity(C1,Name$)
Stat= DeleteEntity(Pc)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(C1) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("torus")
	Stat= AddItemToUndo(WsUBCreateMode,C1)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
GOTO Cloop

Leave:!
Stat=DeleteEntity(Pt)

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