
! script name: vcontours.d/onestepprofile
! var_topic: construct a one step profile.

!A
!A NAME:
!A
!A 	One step profile	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A~ image location - images/onestepprofile.gif
!A
!B INSTRUCTIONS:
!B
!B
!B 	LOCATION POINT: Pick the location point of the trapezoid.
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: One step profile ")

DIM Answer$[256]
DIM Destination$[256]
DIM Length1_var$[256]
DIM Length2_var$[256]
DIM Dia1_var$[256]
DIM Dia2_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=","")
Dia1=InputRadius("DIAMETER 1",WsDiaInput)
IF (ExitScript(Destination$)) THEN Leave
No_dia1_var= LastVariableInput(Dia1_var$)
C1= LastPickEnt
IF ValidGeometry(C1) THEN
        IF NOT ValidDependency(C1) THEN Rect_loop
        No_dia1_var=0
        Stat= EntityNameCheck(C1,Dia1_var$)
END IF

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(2)
Length1=GetValue("LENGTH 1")
IF ExitScript(Destination$) THEN Leave
No_length1_var= LastVariableInput(Length1_var$)


Stat=SetInputFormat("n4=","")
Dia2=InputRadius("DIAMETER 2",WsDiaInput)
IF (ExitScript(Destination$)) THEN Leave
No_dia2_var= LastVariableInput(Dia2_var$)
C1= LastPickEnt
IF ValidGeometry(C1) THEN
        IF NOT ValidDependency(C1) THEN Rect_loop
        No_dia2_var=0
        Stat= EntityNameCheck(C1,Dia2_var$)
END IF


Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(3)
Length2=GetValue("LENGTH 2")
IF ExitScript(Destination$) THEN Leave
No_length2_var= LastVariableInput(Length2_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: One step 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_length1_var THEN
        V1= FreeParameter("Length 1",Length1)
ELSE
        V1= FreeParameter("Length 1",Length1_var$)
END IF
IF No_length2_var THEN
        V2= FreeParameter("Length 2",Length2)
ELSE
        V2= FreeParameter("Length 2",Length2_var$)
END IF
V3= FreeParameter("Corner radius (CW)",Radius)
V4= FreeParameter("Corner radius (CCW)",Radius)
V5= FreeParameter("Angle",Angle)
V10= FreeParameter("Taper 1 ",Taper1)
V11= FreeParameter("Taper 2 ",Taper2)
IF No_dia1_var THEN
       	V7= FreeParameter("Diameter 1",Dia1)
	IF No_dia2_var THEN
       		 V8= FreeParameter("Diameter 2",Dia2)
		 C1= OneStepProfile(V0,Pc,V7,V1,V8,V2,V3,V4,V5,V10,V11)
	ELSE
		 C1= OneStepProfile(V0,Pc,V7,V1,Dia2_var$,V2,V3,V4,V5,V10,V11)
	END IF
ELSE
	IF No_dia2_var THEN
       	   V8= FreeParameter("Diameter 2",Dia2)
	   C1= OneStepProfile(V0,Pc,Dia1_var$,V1,V8,V2,V3,V4,V5,V10,V11)
	ELSE
	   C1= OneStepProfile(V0,Pc,Dia1_var$,V1,Dia2_var$,V2,V3,V4,V5,V10,V11)
	END IF
END IF
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("one step profile")
	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
