
! script name: vlathe.d/undercut_contour
! var_topic: offset - generate an undercut contour.an undercut contour.an undercut contour.an undercut contour.

!A
!A NAME:
!A
!A 	UNDERCUT CONTOUR     VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script generates an undercut contour. 
!A
!A
!B INSTRUCTIONS:
!B
!B      Forward OR Reverse:
!B 		F - Forward will generate a path which has the same direction
!B 		    as the contour.
!B 		R - Reverse will generate a path which is in the opposite
!B 		    direction of the contour.
!B
!B	Longitudinal or Radial: Specify if this is a longitudinal or radial
!B				under cut.
!B
!B
!B 	PICK CONTOUR: Pick the contour.
!B
!B
!C NOTES:
!C
!C	The direction Forward or Reverse is the direction that the undercut
!C	was generated in by the longitudinal cycle.
!C

Stat=ChangeLabelStr("ScriptNameStatus","Function: Undercut contour ")

DIM Destination$[256]
DIM Answer$[256]
DIM Contour$[256]
DIM Angle_var$[256]
DIM Ucutnum$[256]
DIM Name$[256]
INTEGER Id_contour


ActivateUndo
Restart:!
Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave

Stat=SetInputFormat("a1=",",F,R,")
Stat=NamedVarStr("lathe direction",WsLatheVars,"F",Answer$)
Stat=SetEqualsValue(0,Answer$)
Stat=GetValue("Forward OR Reverse",Answer$)
IF ExitScript(Destination$) THEN Leave
Ent= CreateVariable("lathe direction",WsLatheVars,Answer$)
IF (Answer$="F") THEN
        Direction=WsForward
ELSE
        Direction=WsReverse
END IF

Stat= SetInputFormat("a1=",",L,R,")
Stat= NamedVarStr("under type",WsLatheVars,"L",Answer$)
Stat= SetEqualsValue(0,Answer$)
Stat= GetValue("Longitudinal or Radial ",Answer$)
IF ExitScript(Destination$) THEN Leave
Ent= CreateVariable("under type",WsLatheVars,Answer$)
Long= (Answer$="L")
Rough_cycle= WsLongitudinalTurn*Long+ WsRadialTurn*(NOT Long)

Id_contour=NamedVarVal("contour type",WsLatheVars,0)
Stat= SetEqualsValue(0,RPT$("I",Id_contour)&RPT$("O",NOT Id_contour))
Stat= SetInputFormat("a1=",",I,O,")
Stat= GetValue("Id or Od cycle",Answer$)
IF ExitScript(Destination$) THEN Leave
Id_contour= (Answer$="I")
Unum= Id_contour
Ent= CreateVariable("contour type",WsLatheVars,Unum)
IF Id_contour THEN
	Pen_color=WsConvCutPen+1
ELSE
	Pen_color=WsClimbCutPen+1
END IF

Pen_color=Pen_color+3
Stat=SetInputFormat("n0=","")
Upath_num=NamedVarVal("undercut number",WsLatheVars,1.)
Stat=SetEqualsValue(Upath_num)
Upath_num=GetValue("UNDERCUT NUMBER, (0=All)",Answer$)
IF ExitScript(Destination$) THEN Leave
No_ucut_var= LastVariableInput(Upathnum$)
Ent=CreateVariable("undercut number",WsLatheVars,Upath_num)


Stat=SetInputFormat("n4=","")
Uncut_angle=NamedVarVal("tool clearance angle",WsLatheVars,180.)
Stat=SetAngleEquals(Uncut_angle)
Uncut_angle=InputAngle("TOOL CLEARANCE ANGLE")
IF ExitScript(Destination$) THEN Leave
Uncut_angle=Uncut_angle MOD 360
No_angle_var= LastVariableInput(Angle_var$)
L1= LastPickEnt
IF ValidGeometry(L1) THEN
        IF NOT ValidDependency(L1) THEN Angle_ques
        Stat= EntityNameCheck(L1,Angle_var$)
        No_angle_var=0
END IF
Ent= CreateVariable("tool clearance angle",WsLatheVars,Uncut_angle)


Pick_loop:!
Pick_contour:!
Contour=PickGroupEnt("PICK CONTOUR")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(Contour) THEN Pick_contour
Stat=EntityNameCheck(Contour,Contour$)


Stat= SetCurrentColor(Pen_color)
PlotOff
Stat= GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("LATHE UNDERCUT CONTOUR: "&Answer$)
Stat= SetRecDelLastExec
Stat= NullReference(Contour$)
V2= FreeParameter("Direction",Direction)
V3= FreeParameter("Id contour",Id_contour)
IF No_ucut_var THEN
        V4= FreeParameter("Undercut number",Upath_num)
ELSE
        V4= FreeParameter("Undercut number",Upathnum$)
END IF
V6= FreeParameter("Quadrant",1)
IF No_angle_var THEN
        V7= FreeParameter("Tool clearance angle",Uncut_angle)
ELSE
        V7= FreeParameter("Tool clearance angle",Angle_var$)
END IF
Path= UndercutPath(Contour$,Rough_cycle,V4,V3,V6,V7)
Stat= AutoNameGroup(Path,Name$)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
PlotOn
IF NOT ValidGeometry(Path) THEN
        DelLastVarRecord
ELSE
        ActivateUndo
        Stat= AdvanceUndoNumber("undercut contour")
        Stat= AddGroupToUndo(WsUBCreateMode,Path,1,WsTrue)
        Stat= AddItemToUndo(WsUBCreateMode,Curr_record)

        Stat= PlotEntity(Path)
END IF
GOTO Pick_loop


Leave:!
PlotOn
Stat=SetInputFormat("n4","")
Stat=DeleteEntity(Pt)
LowerSelectBox
IF NOT LEN(Destination$) THEN
	  LOAD "typecontrol"
ELSE
	  LOAD Destination$
END IF
END

