
! script name: dyn_solids.d/dyntorus
! 3dtopic: construct torus

!A
!A NAME:
!A
!A 	Dynamic Torus: Define
!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
!B 		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 angle of the torus.
!B
!B 	AXIAL ANGULAR EXTENT: Enter the number of degrees
!B 		and the direction ( + CCW, - CW ) from the starting
!B 		axial angle to the ending axial angle.  The axial
!B 		angular extent determines the ending axial angle.
!B
!B 	STARTING RADIAL ANGLE: Enter the starting angle of the tube.
!B
!B 	RADIAL ANGULAR EXTENT: Enter the number of degrees
!B 		and the direction ( + CCW, - CW ) from the starting
!B 		radial angle to the ending radial angle.  The radial
!B 		angular extent determines the ending radial angle.
!B
!B 	ROTATION ANGLE: Enter the orientation angle of the axis
!B 		of the torus in the XY plane.
!B
!B 	X AXIS TILT ANGLE: This represents the angle of tilt
!B 		of the axis of the torus around the X axis.
!B
!B 	Y AXIS TILT ANGLE: This represents the angle of tilt
!B 		of the axis of 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/dyninput.hlp

Stat=ChangeLabelStr("ScriptNameStatus","Function: dynamic torus ")

DIM Destination$[256]
DIM Answer$[256]
REAL Params(0:10)

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

Stat= GLPlotOn
Start:!
Stat=SetPickMask(WsPickNoSurf)
ActivateUndo
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,Dynamic_angle)
Stat= SetDefaults(WsDynamicAng2Incr,Dynamic_angle)
Stat= SetDefaults(WsDynamicData1,Dynamic_angle)
Stat= SetDefaults(WsDynamicData2,Dynamic_angle)


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

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

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

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

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

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


Tilt_angles:!
Stat=SetInputFormat("n4b=","")
Stat=SetAngleEquals(Zangle)
Zangle=InputAngle("ROTATION ANGLE ( 0 90 180 270 ) ",WsSigned)
IF ExitScript(Destination$) THEN Leave

Stat=SetAngleEquals(Xangle)
Xangle=InputAngle("X AXIS TILT ANGLE ( 0 90 180 270 ) ",WsSigned)
IF ExitScript(Destination$) THEN Leave

Stat=SetAngleEquals(Yangle)
Yangle=InputAngle("Y AXIS TILT ANGLE ( 0 90 180 270 ) ",WsSigned)
IF ExitScript(Destination$) THEN Leave


Place_torus:!

PlotOff
Pref= PointXYZ(0,0,0)
Pdest= CopyEntity(Pref)
Stat= MakeInvisible(Pref)
Stat= MakeInvisible(Pdest)
T1=AngleTransform(Pref,Xangle,Yangle,Zangle,WsWorkplaneVals)
E1=Torus(T1,R1,R2,Axial_astart,axial_angle,radial_astart,radial_angle)
Stat= MakeInvisible(E1)
PlotOn

Vnum= LastPickView
Params(0)= R1
Params(1)= R2
Params(2)= Axial_astart
Params(3)= Axial_angle
Params(4)= Radial_astart
Params(5)= Radial_angle
Params(6)= Xangle
Params(7)= Yangle
Params(8)= Zangle
Num_params=9
Stat=SetInputFormat("n4b","")
Stat=DynamicEntity(Vnum,E1,Pref,Pdest,WsDynamicTorus,"PICK REFERENCE ",Params,Num_params)
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
S1=WPKMakeBsurf(E1)
Stat= DeleteEntity(E1,WsTrue)

ActivateUndo
Stat= AdvanceUndoNumber("torus sheet body")
Stat= AddItemToUndo(WsUBPKSessionMark)
WPKErrorCheck
GOTO Place_torus

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


