
! script name: dyn_shapes.d/dynanicelbow
! topic: one step profile contour

!A
!A NAME:
!A
!A 	Elbow contour
!A
!A DESCRIPTION:
!A
!A	This script constructs a elbow contour. A contour in the shape
!A	of an L.
!A
!A~ image location - images/elbowprofile.gif
!A
!B INSTRUCTIONS:
!B
!B	FIRST LEG WIDTH: Width of the first len end.
!B
!B	SECOND LEG WIDTH: Width of the second len end.
!B
!B	START POINT: Pick the start point.
!B
!B	END POINT: Pick the end point.
!B
!B
!C NOTES:
!C	
!C	The following features are changeable by Free Parameters.
!C
!C		Shape type:  1 sharp or round corner. 11 chamfer corner.
!C		First Leg Angle: Angle of first leg. Default 0.0.
!C		Second Leg Angle: Angle of second leg. Default 90.0.
!C		Inside corner radius: Interior radius at junction of legs.
!C		Outside corner radius: Exterior radius at junction of legs.
!C		Orient angle: Orientation angle of shape.
!C
!C	The key controls are:
!C
!C		< >  First leg width +/-
!C		{ }  Second leg width +/-
!C		6 4  First Leg Angle
!C		8 2  Second Leg Angle
!C		9 7  Outside corner radius
!C		3 1  Inside corner radius
!C		/ *  Corner radius
!C		+ -  Shape Type
!C		F G  0 deg 90 deg corner or 90 deg 0 deg corner.
!C
!C
!C
!C
!C
!C
!# see also - points.d/dyninput.hlp

Stat=ChangeLabelStr("ScriptNameStatus","Function: elbow two points ")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Point1$[256]
DIM Point2$[256]
REAL Params(0:20)



IF ARGC=2 THEN
        Answer$= UPC$(ARGV(1))
	Shape_type= VAL(Answer$)
ELSE
        Shape_type=1
END IF


Start:!
Stat=SetPickMask(WsPickNoSurf)
ActivateUndo
Dynamic_length1= GetDefault(WsDynamicLength1)
Dynamic_length2= GetDefault(WsDynamicLength2)
Dynamic_radius= GetDefault(WsDynRadiusDefault)
Dynamic_data1= GetDefault(WsDynamicData1)
Dynamic_data2= GetDefault(WsDynamicData2)
Dynamic_data3= GetDefault(WsDynamicData3)
Dynamic_data4= GetDefault(WsDynamicData4)
Dynamic_angle1= GetDefault(WsDynamicAng1Incr)
Dynamic_angle2= GetDefault(WsDynamicAng2Incr)

Stat= SetDefaults(WsDynamicLength1,Dynamic_length1)
Stat= SetDefaults(WsDynamicLength2,Dynamic_length1)
Stat= SetDefaults(WsDynamicData1,Dynamic_radius)
Stat= SetDefaults(WsDynamicData2,Dynamic_radius)
Stat= SetDefaults(WsDynamicData3,Dynamic_radius)
Stat= SetDefaults(WsDynamicData4,1)
Stat= SetDefaults(WsDynamicAng1Incr,1)
Stat= SetDefaults(WsDynamicAng2Incr,1)

Rect_loop:!


Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(2)
Width1=GetValue("FIRST LEG WIDTH")
IF ExitScript(Destination$) THEN Leave


Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(2)
Width2=GetValue("SECOND LEG WIDTH")
IF ExitScript(Destination$) THEN Leave

Ask_radius_ccw:Stat=SetInputFormat("n4=","")
Stat=SetRadiusEquals(Radius_ccw)
Radius_ccw=InputRadius("INSIDE CORNER RADIUS")
IF (ExitScript(Destination$)) THEN Leave

Ask_radius_cw:Stat=SetInputFormat("n4=","")
Stat=SetRadiusEquals(Radius_cw)
Radius_cw=InputRadius("OUTSIDE CORNER RADIUS")
IF (ExitScript(Destination$)) THEN Leave


Pick_axis:!
Stat=DynLabel("W1:"&VAL$(Width1)&":W2:"&VAL$(Width2)&":Irad:"&VAL$(Radius_ccw)&":Orad:"&VAL$(Radius_cw))
PlotOn
stat= SetInputFormat("n4b","")
Stat= PointInputMode(1)
Ps=XyzInput("STARTING",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Ps) THEN Circle_loop
Stat=SetLastPoint(Ps)

PlotOff
Corner_rad= 0.0
Angle= 0.0
Angle1= 0.0
Angle2= 90.0
Length2= 3.0*Width1+ 3.0*Width2+ 3.0
Pe= PtIncrXyz(Ps,Length2,Length2,0.0)
Contour= ElbowProfile2Pts(Shape_type,Ps,Pe,Width1,Width2,Angle1,Angle2,Radius_cw,Radius_ccw,Corner_rad)
IF NOT ValidGeometry(Contour) THEN
	Stat= DeleteEntityList(Ps,Pe)
	GOTO Pick_axis
END IF
Params(0)= Shape_type
Params(1)= Width1
Params(2)= Width2
Params(3)= Angle
Params(4)= Angle1
Params(5)= Angle2
Params(6)= Radius_cw
Params(7)= Radius_ccw
Params(8)= Corner_rad
Stat= MakeInvisible(Contour)
Stat= MakeInvisible(Ps)
Stat= MakeInvisible(Pe)
PlotOn

Vnum= LastPickView
Num_params=3
Stat=SetInputFormat("n4b","")
Stat=DynamicShape(Vnum,Contour,Ps,Pe,WsDynamicElbow,"PICK END POINT ",Params,Num_params)
IF (ExitScript(Destination$)) THEN
	 Stat=DeleteGroup(Contour,WsTrue,WsTrue)
	 Stat= DeleteEntityList(Ps,Pe)
       	 IF Destination$= "BACKUP" THEN Pick_axis
       	 GOTO Leave
END IF
Shape_type= Params(0)
Width1= Params(1)
Width2= Params(2)
Angle= Params(3)
Angle1= Params(4)
Angle2= Params(5)
Radius_cw= Params(6)
Radius_ccw= Params(7)
Corner_rad= Params(8)
Stat=SetLastPoint(Pe)
Stat= DeleteEntityList(Ps,Pe)

Stat= PlotEntity(Contour)
IF ValidGeometry(Contour) THEN
	ActivateUndo
	Stat= AdvanceUndoNumber("elbow")
	Stat= AddGroupToUndo(WsUBCreateMode,Contour,1,WsFalse)
END IF
GOTO Pick_axis

Leave:!
Stat=DynLabel("")
Stat=SetPickMask(WsPickGeometry)
Stat= PointInputMode(0)
Stat= DeleteEntityList(Ps,Pe)
Stat= SetDefaults(WsDynamicLength1,Dynamic_length1)
Stat= SetDefaults(WsDynamicLength2,Dynamic_length2)
Stat= SetDefaults(WsDynamicData1,Dynamic_data1)
Stat= SetDefaults(WsDynamicData2,Dynamic_data2)
Stat= SetDefaults(WsDynamicData3,Dynamic_data3)
Stat= SetDefaults(WsDynamicData4,Dynamic_data4)
Stat= SetDefaults(WsDynamicAng1Incr,Dynamic_angle1)
Stat= SetDefaults(WsDynamicAng2Incr,Dynamic_angle2)

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


