
! script name: pkdyn_solids.d/pkdyncylinder
! solids: construct cylinder of specified length, radius, and orientation

!A
!A NAME:
!A
!A 	Dynamic Cylinder: Define
!A
!A DESCRIPTION:
!A
!A 	This script will construct a cylinder of specified length, radius,
!A 	and orientation at the specified center point.
!A
!A~ image location - images/cylinder.gif
!A
!B INSTRUCTIONS:
!B
!B 	RADIUS: Enter the radius of the cylinder to be constructed.
!B
!B 	LENGTH: Enter the length of the cylinder to be constructed.
!B
!B~ image location - images/AngExtent.gif
!B
!B 	AXIS ROTATION ANGLE: Enter the orientation angle of the axis line of
!B 		the cylinder in the XY plane.
!B
!B 	AXIS TILT ANGLE: This represents the angle of tilt of the axis line
!B 		of the cylinder with respect to the XY plane.
!B
!# see also - points.d/dyninput.hlp
!# see also - htdocs/help.d/parasolids.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: dynamic cylinder ")

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

Units= CurrentUnits
IF Units= WsMetric THEN
        Radius= 25
	Length=100
ELSE
        Radius= 1
	Length=5
END IF

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

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,0.0)
Stat= SetDefaults(WsDynamicAng2Incr,0.0)
Stat= SetDefaults(WsDynamicData1,Dynamic_angle)
Stat= SetDefaults(WsDynamicData2,Dynamic_angle)
Stat= SetDefaults(WsDynamicData3,Dynamic_length)


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

Stat=SetInputFormat("n4b=","")
Stat=SetDepthEquals(Length)
Length=InputDepth("LENGTH")
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



Place_cyl:!
PlotOff
Pref= PointXYZ(0,0,0)
Pdest= CopyEntity(Pref)
Stat= MakeInvisible(Pref)
Stat= MakeInvisible(Pdest)
T1=AngleTransform(Pref,Xangle,0.0,Zangle,WsWorkplaneVals)
E1=Cylinder(T1,Radius,Length,0,360)
Stat= MakeInvisible(E1)
Stat= HideEntity(E1)
PlotOn

Vnum= LastPickView
Params(0)= Radius
Params(1)= Length
Params(2)= 0
Params(3)= 360
Params(4)= Xangle
Params(5)= 0.0
Params(6)= Zangle
Num_params=7
Stat=SetInputFormat("n4b","")
Stat=DynamicEntity(Vnum,E1,Pref,Pdest,WsDynamicCylinder,"PICK REFERENCE ",Params,Num_params,0,WsTrue,WsFalse)
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
Stat=DeleteEntity(Pref)
Stat=DeleteEntity(Pdest)

WPKClearErrorFlag
E2=WPKBasicSolid(E1)
Stat=DeleteEntity(E1)

ActivateUndo
Stat= AdvanceUndoNumber("solid cylinder")
Stat= AddItemToUndo(WsUBPKSessionMark)
WPKErrorCheck
GOTO Place_cyl

Leave:!
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


