
! script name: pkdyn_solids.d/pkdynconeangle
! solids: 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
!# see also - points.d/dyninput.hlp
!# see also - htdocs/help.d/parasolids.htm

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
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,0.0)
Stat= SetDefaults(WsDynamicAng2Incr,0.0)

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


Pick_axis:!
Stat=DynLabel("Radius:"&VAL$(R1)&":Cone angle:"&VAL$(Cone_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,0,360,WsForward)
Stat= MakeInvisible(Axis_line)
Stat= MakeInvisible(C1)
Stat= hideEntity(C1)
Stat= MakeInvisible(Ps)
Stat= MakeInvisible(Pe)
PlotOn

Vnum= LastPickView
Params(0)= R1
Params(1)= Length1
Params(2)= 0.0
Params(3)= 360
Params(4)= Cone_angle
Num_params=5
Stat=SetInputFormat("n4b","")
Stat=DynamicEntity(Vnum,C1,Ps,Pe,WsDynAngleCone,"PICK AXIS ENDPOINT ",Params,Num_params,0,WsTrue,WsFalse)
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)
Cone_angle= Params(4)

Stat=DeleteEntity(Ps)
Stat=DeleteEntity(Pe)
Stat=DeleteEntity(Axis_line)

WPKClearErrorFlag
C2=WPKBasicSolid(C1)
Stat=DeleteEntity(C1)

ActivateUndo
Stat= AdvanceUndoNumber("solid cone")
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
