
! script name: dyn_solids.d/dynaxiscyl
! 3dtopic: construct cylinder along an axis line

!A
!A NAME:
!A
!A 	Dynamic Cylinder: Axis
!A
!A DESCRIPTION:
!A
!A 	This script will construct a cylinder using the line that would be
!A 	created between the two points that are picked, as the axis line of
!A 	the cylinder.  The length of the cylinder is determined by the distance
!A 	between the two points that are picked.
!A
!A~ image location - images/cylaxis.gif
!A
!B INSTRUCTIONS:
!B
!B 	RADIUS: Enter the radius of the cylinder to be constructed.
!B
!B 	STARTING ANGLE: Enter the starting angle of the 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~ image location - images/AngExtent.gif
!B
!B 	AXIS START: Pick the axis start point of the cylinder.
!B
!B 	PICK AXIS ENDPOINT: Pick the axis endpoint for the cylinder.
!B
!C NOTES:
!C
!C 	The U contours of a cylinder are the circles and the V contours
!C 	are the lines.
!C
!# see also - points.d/dyninput.hlp

Stat=ChangeLabelStr("ScriptNameStatus","Function: cylinder along an axis line ")

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

Units= CurrentUnits
IF Units= WsMetric THEN
        Radius= 25
ELSE
        Radius= 1
END IF

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

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

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

Stat= SetDefaults(WsDynamicLength1,Dynamic_radius)
Stat= SetDefaults(WsDynamicAng1Incr,Dynamic_angle)
Stat= SetDefaults(WsDynamicAng2Incr,Dynamic_angle)

Cloop:!
Stat=SetInputFormat("n4b=","")
Stat=SetRadiusEquals(Radius)
Radius=InputRadius("RADIUS")
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=GetValue("ANGULAR EXTENT ( 90 180 360 ) ",Answer$)
IF ExitScript(Destination$) THEN Leave

Pick_axis:!
Stat=DynLabel("Rad:"&VAL$(Radius)&":As:"&VAL$(Astart)&":Angle:"&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= 2.0*Radius
Pe= PtIncrXyz(Ps,0.0,Length1,0.0)
Axis_line= LineTwoPoints(Ps,Pe)
C1=AxisLineCylinder(Axis_line,Radius,Astart,Angle,WsForward)
Stat= MakeInvisible(Axis_line)
Stat= MakeInvisible(C1)
Stat= MakeInvisible(Ps)
Stat= MakeInvisible(Pe)
PlotOn

Vnum= LastPickView
Params(0)= Radius
Params(1)= Length1
Params(2)= Astart
Params(3)= Angle
Num_params=4
Stat=SetInputFormat("n4b","")
Stat=DynamicEntity(Vnum,C1,Ps,Pe,WsDynAxisCylinder,"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
Radius= Params(0)
Length1= Params(1)
Astart= Params(2)
Angle= Params(3)
Stat=DeleteEntity(Ps)
Stat=DeleteEntity(Pe)
Stat=DeleteEntity(Axis_line)

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

ActivateUndo
Stat= AdvanceUndoNumber("cylinder sheet body")
Stat= AddItemToUndo(WsUBPKSessionMark)
WPKErrorCheck

GOTO Pick_axis

Leave:!
Stat=DynLabel("")
Stat=SetPickMask(WsPickGeometry)
Stat= SetDefaults(WsDynamicLength1,Dynamic_length1)
Stat= SetDefaults(WsDynamicAng1Incr,Dynamic_angle1)
Stat= SetDefaults(WsDynamicAng2Incr,Dynamic_angle2)
Stat=DeleteEntity(Ps)
Stat=DeleteEntity(Pe)
Stat=DeleteEntity(Axis_line)

IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	IF Destination$= "SCRIPTSTART" THEN Start
	IF Destination$= "BACKUP" THEN Start
	LOAD Destination$
END IF
END
