
! script name: dyn_solids.d/dyncone
! 3dtopic: construct cone of specified length, start radius, end radius, orientation

!A
!A NAME:
!A
!A 	Dynamic Cone: Define
!A
!A DESCRIPTION:
!A
!A 	This script constructs a cone of specified length, starting radius,
!A 	ending radius, and orientation at the specified center point.
!A
!A~ image location - images/DefineCone.gif
!A
!B INSTRUCTIONS:
!B
!B 	START RADIUS: Enter the starting radius of the cone.
!B
!B 	END RADIUS: Enter the ending radius of the cone.
!B
!B 	LENGTH: Enter the length of the cone to be constructed.
!B
!B 	STARTING ANGLE ( 0 90 180 270 ): Enter the starting angle of the cone.
!B
!B 	ANGULAR EXTENT ( 90 180 360 ): Enter the number of degrees and the
!B 		direction ( + CCW, - CW ) from the starting angle to the
!B 		ending angle.  The angular extent determines the ending angle.
!B
!B~ image location - images/AngExtent.gif
!B
!B 	AXIS ROTATION ANGLE ( 0 90 180 270 ): Enter the orientation angle of
!B 		the axis line of the cone in the XY plane.
!B
!B 	AXIS TILT ANGLE ( 0 90 180 270 ): This represents the angle of tilt
!B 		of the axis line of the cone with respect to the XY plane.
!B
!B 	AXIS ROLL ANGLE ( 0 90 180 270 ): This represents the roll angle
!B 		around the axis line of the cone.
!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: Dynamic cone ")

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

Units= CurrentUnits
IF Units= WsMetric THEN
        R1= 25
        R2= 25
	Length= 100
ELSE
        R1= 1
        R2= 1
	Length= 5
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_data1= GetDefault(WsDynamicData1)
Dynamic_data2= GetDefault(WsDynamicData2)
Dynamic_data3= GetDefault(WsDynamicData3)

Dynamic_radius= GetDefault(WsDynRadiusDefault)
Dynamic_angle= GetDefault(WsDynAngleDefault)
Dynamic_length= GetDefault(WsDynLengthDefault)

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= SetDefaults(WsDynamicData3,Dynamic_length)



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

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

Stat=SetInputFormat("n4b=","")
Stat=SetEqualsValue(Length)
Length=GetValue("LENGTH",Answer$)
IF ExitScript(Destination$) THEN Leave

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

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


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

Zangle=Zangle1-90

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

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


Place_cone:!
Stat=DynLabel("R1:"&VAL$(R1)&":R2:"&VAL$(R2)&":L:"&VAL$(Length)&":RA:"&VAL$(Zangle+90)&":TA:"&VAL$(Xangle))
PlotOff
Pref= PointXYZ(0,0,0)
Pdest= CopyEntity(Pref)
Stat= MakeInvisible(Pref)
Stat= MakeInvisible(Pdest)
T1=AngleTransform(Pref,Xangle,Yangle,Zangle,WsWorkplaneVals)
E1=Cone(T1,R1,R2,Length,Astart,Angle_extent)
Stat= MakeInvisible(E1)
PlotOn

Vnum= LastPickView
Params(0)= R1
Params(1)= R2
Params(2)= Length
Params(3)= Astart
Params(4)= Angle_extent
Params(5)= Xangle
Params(6)= Yangle
Params(7)= Zangle
Num_params=8
Stat=SetInputFormat("n4b","")
Stat=DynamicEntity(Vnum,E1,Pref,Pdest,WsDynamicCone,"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
R1=Params(0)
R2=Params(1)
Length=Params(2)
Astart=Params(3)
Angle_extent=Params(4)
Xangle=Params(5)
Yangle=Params(6)
Zangle=Params(7)

Stat=DeleteEntity(Pref)
Stat=DeleteEntity(Pdest)

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

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

Leave:!
Stat=DynLabel("")
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)
Stat= SetDefaults(WsDynamicData3,Dynamic_data3)
IF NOT LEN(Destination$) THEN
        LOAD "typecontrol"
ELSE
        IF Destination$= "SCRIPTSTART" THEN Start
        IF Destination$= "BACKUP" THEN Start
        LOAD Destination$
END IF
END

