
! script name: dyn_solids.d/dynconeangle
! 3dtopic: construct cone defined by an angle

!A
!A NAME:
!A
!A 	Dynamic Cone: Angle
!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, with specified starting radius and
!A 	cone angle (taper).  The length of the cone is determined by the length
!A 	of the axis line picked; the ending radius is determined by the cone
!A 	angle, the starting radius, and the length of the cone.
!A
!B INSTRUCTIONS:
!B
!B 	STARTING RADIUS: Enter the starting radius of the cone.
!B
!B 	CONE ANGLE: Enter the angle of taper 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
!B
!C NOTES:
!C
!C 	The U contours of a cone are the circles and the V contours are the
!C 	lines.
!C
!# see also - points.d/dyninput.hlp

Stat=ChangeLabelStr("ScriptNameStatus","Function: cone defined by an angle ")

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

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

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

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_angle)
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

Ask_angle:Stat=SetAngleEquals(Cone_angle)
Cone_angle=InputAngle("CONE ANGLE")
IF ExitScript(Destination$) THEN Leave
IF (Cone_angle> 179.99) OR (Cone_angle< -179.99) THEN Ask_angle

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("R:"&VAL$(R1)&":CA:"&VAL$(Cone_angle)&":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= .005
Pe= PtIncrXyz(Ps,0.0,Length1,0.0)
Axis_line= LineTwoPoints(Ps,Pe)
C1=ConeRadiusAngle(Axis_line,R1,Cone_angle,Astart,Angle,WsForward)
Stat= MakeInvisible(Axis_line)
Stat= MakeInvisible(C1)
Stat= MakeInvisible(Ps)
Stat= MakeInvisible(Pe)
PlotOn

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

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=DeleteEntity(Ps)
Stat=DeleteEntity(Pe)
Stat=DeleteEntity(Axis_line)
Stat= SetDefaults(WsDynamicLength2,Dynamic_angle1)
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	IF Destination$= "SCRIPTSTART" THEN Start
        IF Destination$= "BACKUP" THEN Start
	LOAD Destination$
END IF
END
