
! script name: dyn_solids.d/dyncylrev
! 3dtopic: construct revolution for cylinder

!A
!A NAME:
!A
!A 	Dynamic Revolution: cylinder with corner radii along Axis
!A
!A DESCRIPTION:
!A
!A 	This script will construct a cylinder using the line that is graphically
!A 	picked as the axis of the cylinder.  The length of the cylinder 
!A	is determined by the length of the axis line picked.  The type of
!A 	cylinder constructed will depend on the pass parameter.
!A
!B INSTRUCTIONS:
!B
!B 	RADIUS: Enter the radius of the cylinder.
!B
!B 	CORNER RADIUS: Enter the corner radius of the cylinder.
!B
!B 	STARTING ANGLE  ( 0 90 180 270 ): Enter the starting angle of the
!B 		cylinder.
!B
!B 	ANGULAR EXTENT: Enter the number of degrees and the direction
!B 		( + CCW, - CW ) from the starting angle to the ending angle.
!B 		The angular extent determines the ending angle.
!B
!B 	AXIS START X,Y,Z: Enter the axis start point of the cylinder.
!B
!B 	PICK AXIS ENDPOINT: Pick the axis endpoint.
!B
!C NOTES:
!C
!C 	The U contours of a cylinder constructed as a revolution are the lines
!C 	and the V contours are the circles.
!C
!D 	This script has 3 pass parameters available.  They are:
!D 		0 - ClosedEnds
!D 		1 - OpenFrontEnd
!D 		2 - OpenBackEnd
!D
!# see also - points.d/dyninput.hlp

Stat=ChangeLabelStr("ScriptNameStatus","Function: dynamic revolution cylinder ")

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


C_type=0
IF ARGC>1 THEN
	Type$=ARGV(1)
	C_type=VAL(Type$)
END IF

Units= CurrentUnits
IF Units= WsMetric THEN
        R1= 25
        R2= 25
        R3= 3
ELSE
        R1= 1
        R2= 1
        R3= 0.125
END IF

Start:!
Stat=SetPickMask(WsPickNoSurf)
ActivateUndo
Astart= 0
Angle= 180

Dynamic_length1= GetDefault(WsDynamicLength1)
Dynamic_length2= GetDefault(WsDynamicLength2)
Dynamic_angle1= GetDefault(WsDynamicAng1Incr)
Dynamic_angle2= GetDefault(WsDynamicAng2Incr)

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)

Cloop:!

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

Stat=SetRadiusEquals(R3)
R3=InputRadius("CORNER RADIUS")
IF ExitScript(Destination$) THEN Leave
R3=ABS(R3)

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

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


Pick_axis:!
Stat=SetInputFormat("n4b","")
Ps=XyzInput("AXIS START",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Ps) THEN Pick_axis

Stat=SetLastPoint(Ps)

PlotOff
length1= 2.0*R1
Pe= PtIncrXyz(Ps,0.0,Length1,0.0)
Axis_line= LineTwoPoints(Ps,Pe)
C1=RevolutionCone(Axis_line,C_type,R1,R2,Astart,Angle,R3,WsForward)
Stat= MakeInvisible(Axis_line)
Stat= MakeInvisible(C1)
Stat= MakeInvisible(Ps)
Stat= MakeInvisible(Pe)
PlotOn

Vnum= LastPickView
Params(0)= C_type
Params(1)= R1
Params(2)= Length1
Params(3)= Astart
Params(4)= Angle
Params(5)= R3
Num_params=6
Stat=SetInputFormat("n4b","")
Stat=DynamicEntity(Vnum,C1,Ps,Pe,WsDynRevCylinder,"PICK AXIS ENDPOINT ",Params,Num_params)
IF (ExitScript(Destination$)) THEN
        Stat=DeleteEntity(Axis_line,WsTrue)
        Stat=DeleteEntity(C1,WsTrue)
	Stat=DeleteEntity(Ps)
	Stat=DeleteEntity(Pe,WsTrue)
	IF Destination$= "BACKUP" THEN Pick_axis
        GOTO Leave
END IF
Stat=DeleteEntity(Ps)
Stat=DeleteEntity(Pe)
Stat=DeleteEntity(Axis_line)
Stat= PlotEntity(C1)

ActivateUndo
Stat= AdvanceUndoNumber("cylinder")
Stat= AddItemToUndo(WsUBCreateMode,C1)

GOTO Pick_axis

Leave:!
Stat=SetPickMask(WsPickGeometry)
Stat= SetDefaults(WsDynamicLength1,Dynamic_length1)
Stat= SetDefaults(WsDynamicLength2,Dynamic_length2)
Stat= SetDefaults(WsDynamicAng1Incr,Dynamic_angle1)
Stat= SetDefaults(WsDynamicAng2Incr,Dynamic_angle2)
Stat=SetInputFormat("n4","")
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	IF Destination$= "SCRIPTSTART" THEN Start
        IF Destination$= "BACKUP" THEN Start
	LOAD Destination$
END IF
END
