
! script name: dyn_solids.d/dynconerev
! 3dtopic: construct revolution for cone

!A
!A NAME:
!A
!A 	Dynamic Revolution: Cone with corner radii along Axis
!A
!A DESCRIPTION:
!A
!A 	This script will construct a cone using the line that is graphically
!A 	picked as the axis of the cone.  The length of the cone is determined
!A 	by the length of the axis line picked.
!A
!B INSTRUCTIONS:
!B
!B 	STARTING RADIUS: Enter the starting radius of the cone.
!B
!B 	ENDING RADIUS: Enter the ending radius of the cone.
!B
!B 	CORNER RADIUS: Enter the corner radius of the cone.
!B
!B 	STARTING ANGLE: Enter the starting angle of the cone.
!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
!C NOTES:
!C
!C 	The U contours of a cone 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
!# see also - points.d/dyninput.hlp

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

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

Stat= GLPlotOn
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("STARTING RADIUS")
IF ExitScript(Destination$) THEN Leave
R1=ABS(R1)

Stat=SetRadiusEquals(R2)
R2=InputRadius("ENDING RADIUS")
IF ExitScript(Destination$) THEN Leave
R2= ABS(R2)

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=DynLabel("R1:"&VAL$(R1)&":R2:"&VAL$(R2)&":CR:"&VAL$(R3)&":As:"&VAL$(Astart)&":A:"&VAL$(Angle))
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= R1+R2
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)= R2
Params(3)= Length1
Params(4)= Astart
Params(5)= Angle
Params(6)= R3
Num_params=7
Stat=SetInputFormat("n4b","")
Stat=DynamicEntity(Vnum,C1,Ps,Pe,WsDynRevCone,"PICK AXIS ENDPOINT ",Params,Num_params)
IF (ExitScript(Destination$)) THEN
        Stat=DeleteEntity(C1,WsTrue)
	Stat=DeleteEntity(Ps)
	Stat=DeleteEntity(Pe,WsTrue)
	Stat=DeleteEntity(Axis_line,WsTrue)
	IF Destination$= "BACKUP" THEN Pick_axis
        GOTO Leave
END IF
C_type=Params(0)
R1=Params(1)
R2=Params(2)
Length1=Params(3)
Astart=Params(4)
Angle=Params(5)
R3=Params(6)
Stat=DeleteEntity(Ps)
Stat=DeleteEntity(Pe)
Stat=DeleteEntity(Axis_line)

WPKClearErrorFlag
S1=WPKMakeBsurf(C1)
Stat= DeleteEntity(C1,WsTrue)

ActivateUndo
Stat= AdvanceUndoNumber("cone sheet body")
Stat= AddItemToUndo(WsUBPKSessionMark)
WPKErrorCheck
GOTO Pick_axis

Leave:!
Stat=DynLabel("")
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
