
! script name: vcontours.d/twostepprofile
! var_topic: construct a two step profile.

!A
!A NAME:
!A
!A 	Two step contour	VARIATIONAL	
!A
!A DESCRIPTION:
!A
!A	This script constructs a contour consisting of two steps
!A	in a shaft. May be used as a turning profile or to draw 
!A	shapes like a counterbore.
!A
!A~ image location - images/twostepprofile.gif
!A
!B INSTRUCTIONS:
!B
!B	DIAMETER 1: First diameter.
!B
!B	LENGTH 1: Length along first diameter.
!B
!B	DIAMETER 2: Second diameter.
!B
!B	LENGTH 2: Length along second diameter.
!B
!B	DIAMETER 3: Second diameter.
!B
!B	LENGTH 3: Length along second diameter.
!B
!B	LOCATION POINT: Pick the location point.
!B
!B
!C NOTES:
!C
!C	This script can generate the following versions:
!C
!C		type= 1: Complete Profile
!C		type= 2: Upper Half 
!C		type= 3: Lower Half
!C		type= 11: Complete Profile Chamfered
!C		type= 12: Upper Half  Chamfered
!C		type= 13: Lower Half Chamfered
!C		type= 21: Complete Profile Radius CCW Chamfered CW
!C		type= 22: Upper Half  Radius CCW Chamfered CW
!C		type= 23: Lower Half Radius CCW Chamfered CW
!C		type= 31: Complete Profile Radius CW Chamfered CCW
!C		type= 32: Upper Half  Radius CW Chamfered CCW
!C		type= 33: Lower Half Radius CW Chamfered CCW
!C
!C	The following features are controled by Free Parameters:
!C
!C		Shape type: Type of shape. See above. 
!C		Radius CW:  Corner radius or chamfer for CW corners.
!C		Radius CCW: Corner radius or chamfer for CCW corners.
!C		Taper 1:    Taper of first length segment.
!C		Taper 2:    Taper of second length segment.
!C		Taper 3:    Taper of third length segment.
!C
!C
!C	The key controls are:
!C
!C		< >  Diameter 1 +/-
!C		{ }  Diameter 2 +/-
!C		F G  Diameter 3 +/-
!C		6 4  Radius CW
!C		8 2  Radius CCW
!C		9 7  Length 1
!C		3 1  Length 2
!C		/ 1  Length 3
!C		+ -  Shape Type
!C
!C
!# see also - points.d/dyninput.hlp

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

DIM Answer$[256]
DIM Destination$[256]
DIM Length1_var$[256]
DIM Length2_var$[256]
DIM Length3_var$[256]
DIM Dia1_var$[256]
DIM Dia2_var$[256]
DIM Dia3_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$)


Stat=SetInputFormat("n4=","")
Dia3=InputRadius("DIAMETER 3",WsDiaInput)
IF (ExitScript(Destination$)) THEN Leave
No_dia3_var= LastVariableInput(Dia3_var$)
C1= LastPickEnt
IF ValidGeometry(C1) THEN
        IF NOT ValidDependency(C1) THEN Rect_loop
        No_dia3_var=0
        Stat= EntityNameCheck(C1,Dia3_var$)
END IF


Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(3)
Length3=GetValue("LENGTH 3")
IF ExitScript(Destination$) THEN Leave
No_length3_var= LastVariableInput(Length3_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: Two 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
IF No_length3_var THEN
        V3= FreeParameter("Length 3",Length3)
ELSE
        V3= FreeParameter("Length 3",Length3_var$)
END IF
V4= FreeParameter("Corner radius (CW)",Radius)
V5= FreeParameter("Corner radius (CCW)",Radius)
V6= FreeParameter("Angle",Angle)
V11= FreeParameter("Taper 1 ",Taper1)
V12= FreeParameter("Taper 2 ",Taper2)
V13= FreeParameter("Taper 3 ",Taper3)

IF No_dia1_var THEN
       	V8= FreeParameter("Diameter 1",Dia1)
	IF No_dia2_var THEN
       		V9= FreeParameter("Diameter 2",Dia2)
		IF No_dia3_var THEN
       			V10= FreeParameter("Diameter 3",Dia3)
		 	C1= TwoStepProfile(V0,Pc,V8,V1,V9,V2,V10,V3,V4,V5,V6,V11,V12,V13)
		ELSE
		    C1= TwoStepProfile(V0,Pc,V8,V1,V9,V2,Dia3_var$,V3,V4,V5,V6,V11,V12,V13)
		END IF
	ELSE
	   IF No_dia3_var THEN
              V10= FreeParameter("Diameter 3",Dia3)
              C1= TwoStepProfile(V0,Pc,V8,V1,Dia2_var$,V2,V10,V3,V4,V5,V6,V11,V12,V13)
           ELSE
              C1= TwoStepProfile(V0,Pc,V8,V1,Dia2_var$,V2,Dia3_var$,V3,V4,V5,V6,V11,V12,V13)
           END IF
	END IF
ELSE
   IF No_dia2_var THEN
      V9= FreeParameter("Diameter 2",Dia2)
      IF No_dia3_var THEN
         V10= FreeParameter("Diameter 3",Dia3)
         C1= TwoStepProfile(V0,Pc,Dia1_var$,V1,V9,V2,V10,V3,V4,V5,V6,V11,V12,V13)
      ELSE
         C1= TwoStepProfile(V0,Pc,Dia1_var$,V1,V9,V2,Dia3_var$,V3,V4,V5,V6,V11,V12,V13)
      END IF
   ELSE
      IF No_dia3_var THEN
         V10= FreeParameter("Diameter 3",Dia3)
         C1= TwoStepProfile(V0,Pc,Dia1_var$,V1,Dia2_var$,V2,V10,V3,V4,V5,V6,V11,V12,V13)
      ELSE
      C1= TwoStepProfile(V0,Pc,Dia1_var$,V1,Dia2_var$,V2,Dia3_var$,V3,V4,V5,V6,V11,V12,V13)
      END IF
   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("two step")
	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
