
! script name: vcontours.d/elbowprofile
! var_topic: construct a elbow profile  profile.

!A
!A NAME:
!A
!A 	Elbow contour	VARIATIONAL	
!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	X LENGTH: X Length from start point to endpoint.
!B
!B	Y WIDTH: Y width from start point to endpoint.
!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

stat=ChangeLabelStr("ScriptNameStatus","Function: Elbow profile ")

DIM Answer$[256]
DIM Destination$[256]
DIM Length_var$[256]
DIM Width_var$[256]
DIM Width1_var$[256]
DIM Width2_var$[256]
DIM Name$[256]
DIM Center$[256]
DIM Radius_var$[256]

Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave
DEG

ActivateUndo
Use_chamfer= 0
Shape_type=1
Angle= 0.0
IF ARGC> 1 THEN
                Answer$= ARGV(2)
                Shape_type= VAL(Answer$)
END IF


Rect_loop:!

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(2)
XLength=GetValue("X LENGTH")
IF ExitScript(Destination$) THEN Leave
No_length_var= LastVariableInput(Length_var$)


Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(3)
YWidth=GetValue("Y WIDTH")
IF ExitScript(Destination$) THEN Leave
No_width_var= LastVariableInput(Width_var$)


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


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


Pick_point:Stat=SetInputFormat("n4=","")
E1=PickEntity("LOCATION POINT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E1) THEN Pick_point
T= LastPickPara
Pick_return= CurrPickReturn
Stat= EntityNameCheck(E1,Center$)
Pc= ParameterReturnPt(E1,T,Pick_return)
Stat=SetEqualsValue(Radius)
Stat=SetLastPoint(Pc)
Stat= DeleteEntity(Pc)

Angle=0

Stat= GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("CONTOUR: Elbow profile")
Stat= SetRecDelLastExec
SELECT Pick_return
CASE WsGeometryEnd
        Pc= ParameterReturnPt(Center$,T,WsGeometryEnd)
CASE WsGeometryMid
        Pc= ParameterReturnPt(Center$,T,WsGeometryMid)
CASE WsGeomCenter
        Pc= ParameterReturnPt(Center$,T,WsGeomCenter)
END SELECT
V0= FreeParameter("Type",Shape_type)
IF No_length_var THEN
        V1= FreeParameter("X Length",XLength)
ELSE
        V1= FreeParameter("X Length",Length_var$)
END IF
IF No_width_var THEN
        V2= FreeParameter("Y Width",Ywidth)
ELSE
        V2= FreeParameter("Y Width",Width_var$)
END IF
IF No_width1_var THEN
        V3= FreeParameter("First leg width",Width1)
ELSE
        V3= FreeParameter("First leg width",Width1_var$)
END IF
IF No_width2_var THEN
        V4= FreeParameter("Second leg width",Width2)
ELSE
        V4= FreeParameter("Second leg width",Width2_var$)
END IF
V5= FreeParameter("Inside corner radius",0.0)
V6= FreeParameter("Outside corner radius",0.0)
V7= FreeParameter("Corner radius",0.0)
V8= FreeParameter("First leg angle",0.0)
V9= FreeParameter("Second leg angle",90.0)
V10= FreeParameter("Orient angle",Angle)
C1= ElbowProfile(V0,Pc,V1,V2,V3,V4,V8,V9,V6,V5,V7,V10)
Stat= AutoNameGroup(C1,Name$)
Stat= DeleteEntity(Pc)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= PlotEntity(C1)
Stat= PlotEntity(Center$)
IF NOT ValidGeometry(C1) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("elbow")
	Stat= AddGroupToUndo(WsUBCreateMode,C1,1,WsTrue)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
GOTO Pick_point

Leave:!
Stat=DeleteEntity(Pc)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
