
! script name: vlathe.d/finishgrvcont
! var_topic: given a contour, produce a groove finish path.

!A
!A NAME:
!A
!A 	Finish groove a contour .  VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script creates a pathgroup to finish cut a contour with a
!A 	grooving tool. The contour must be "groove like", that is
!A	for an Od groove that the diameter decreases and then it
!A	increases.
!A
!A~ image location - images/fingrvcont.jpg
!A
!B INSTRUCTIONS:
!B
!B	SELECT TOOL: Select the finish grooving tool.
!B
!B 	FINISH ALLOWANCE: Enter the amount of material to remain.
!B
!B 	PICK CONTOUR: Select the contour to be grooved.
!B
!B
!C NOTE:
!C	
!C	The finish cut will start cutting the contour with one side of the 
!C	tool until it its center reaches the split point plus the overlap.
!C	It will then retract, go to the other end of the
!C	contour, and cut with the other side of the tool down to the
!C	where the last cut left off, plus the overlap.
!C	The grooving tool must fit in the groove. This cycle will not
!C	produce a correct path if the tool cannot fit in the location
!C	of the split point.
!C
!# see also - lathe.d/tooltiptan.hlp


Stat=ChangeLabelStr("ScriptNameStatus","Function: finish groove contour ")

DIM Destination$[256], Answer$[256]
DIM Toolname$[256]
DIM Destination$[256]
DIM Answer$[256]
DIM Toolid$[256]
DIM Contour$[256]
DIM Finish_var$[256]
DIM Name$[256]
INTEGER Id_contour


Mode$= ARGV(1)
Current_pen= CurrentColor
Work= CurrentWorkplane
!   StdWorkplane
DEG

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


Animate_tool=1
Units= CurrentUnits
IF Units= WsMetric THEN
	Conv= 25.4
ELSE
	Conv= 1.
END IF

Rapid_linetype= 8
Pen_finpath=21

Cutwidth_def= .15*Conv
Tlwd_def= .5*Conv
Depth_of_cut_def= .2*Conv
Tnose_rad_def= .031*Conv
Allow_def= .04*Conv
Stock_allow= .04*Conv

Clearance= .05*Conv
Chip_clear= .01*Conv
Overlap= .02*Conv
Lead_dist= .05*Conv
Lead_in= 5  ! tangent lead into groove 

Start:!
Stat=ToolSelectBox("TOOLS","selected tool",WsAllGroovers)
IF Stat THEN 
  Stat= MessageFileBox("/usr/weber/database/messages/notoolsloaded","ATTENTION")
  GOTO Leave
END IF
Tool_ques:!
Stat=SetInputFormat("a99","")
Stat=GetValue("GROOVING TOOL",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$= "CANCEL" THEN
                LowerSelectBox
                GOTO Leave
END IF
Toolname$= Answer$
LowerSelectBox

Tool=FindUserData(Toolname$,WsToolData)
Stat=GetUserString(Tool,"Tool type:",Toolid$)
Tnose_rad=ToolNoseRadius(Tool)
Quad=ToolQuadrant(Tool)
Tlwd=ToolWidth(Tool)
Cutwidth=ToolCutWidth(Tool)
IF NOT Cutwidth THEN Cutwidth= Cutwidth_def
IF NOT Tlwd THEN Tlwd= Tlwd_def


Ask_mode:!
IF (Mode$="") THEN
	Stat= SetEqualsValue(0,"O")
	Stat=SetInputFormat("a1=",",O,I,F,")
	Stat=GetValue("GROOVE TYPE Od, Id, Face",Mode$)
	IF (ExitScript(Destination$)) THEN Leave
Set_mode:SELECT Mode$
	CASE "O"
		Mode$="od"
	CASE "I"
		Mode$="id"
	CASE "F"
		Mode$="face"
	CASE ELSE
		Moder$=Mode$
		Mode$=UPC$(Mode$)
		GOTO Setmode
	END SELECT
END IF
Face_groove=(Mode$="face")
Id_groove= (Mode$= "id")

Allow=NamedVarVal("finish allowance",WsSystemVars,Allow_def)
Stat= SetInputFormat("n4=","")
Stat=SetEqualsValue(Allow)
Allow=GetValue("FINISH ALLOWANCE",Answer$)
IF ExitScript(Destination$) THEN Leave
No_finish_var= LastVariableInput(Finish_var$)
Ent=CreateVariable("finish allowance",WsSystemVars,Allow)

Pick_loop:!
Stat= SetInputFormat("n4a1",",T,")
Contour= PickGroupEnt("PICK CONTOUR,   Tool ",0,Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$="T" THEN
        Mode$=""
        GOTO Restart
END IF
IF NOT ValidDependency(Contour) THEN Pick_loop
Stat= EntityNameCheck(Contour,Contour$)
Closed=IsContClosed(Contour)
IF Closed THEN Pick_loop
	


Groove_cycle:!
PlotOff
Stat= GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("LATHE CONTOUR GROOVE: Finish "&Mode$&" "&Toolname$)
Stat= SetRecDelLastExec
Stat= NullReference(Contour$)
Tool=FindUserData(Toolname$,WsToolData)
V1= FreeParameter("Tool nose radius",ToolNoseRadius(Tool))
V2= FreeParameter("Tool quadrant",ToolQuadrant(Tool))
V3= FreeParameter("Face groove",Face_groove)
V4= FreeParameter("Id groove",Id_groove)
IF No_finish_var THEN
         V5= FreeParameter("Finish allowance",Allow)
ELSE
         V5= FreeParameter("Finish allowance",Finish_var$)
END IF
V6= FreeParameter("Cut type",Cut_type)
V7= FreeParameter("Chip clearance",Chip_clear)
V8= FreeParameter("Tool width",ToolWidth(Tool))
V9= FreeParameter("Tool clearance",Clearance)
V10= FreeParameter("Overlap",Overlap)
V11= FreeParameter("Lead in type",Lead_in)
V12= FreeParameter("Lead in dist",Lead_dist)
V13= FreeParameter("Negative diameter",NegDiaCheck(V3,V4,V2))
V14= FreeParameter("Finish path color",Pen_finpath)
V15= FreeParameter("Collision point color",7)
Gdef= GrooveDefinition(WsChamferGroove,V3,V4,V13,0,0,0,0,0)
Stat= GrooveDefCutInfo(Gdef,V6,V2,V8,V1,0,0,V5,V9,V7)
Path= GrooveFinishCont(Gdef,Contour$,0,V10,V11,V12)
Stat= DeleteEntity(Gdef)
Stat= SetColor(Path,V14)
Stat= AutoNameGroup(Path,Name$)
Stat= AssociateTool(Path,Tool)
P1= LthToolInterfere(Tool,Path,Contour$)
Stat= SetColor(P1,V15)
Stat= SetLineType(P1,11)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
PlotOn
IF NOT ValidGeometry(Path) THEN
     DelLastVarRecord
     Stat= MessageStringBox("NO PATH CREATED: TOOL DOES NOT FIT","ATTENTION")
ELSE
        ActivateUndo
        Stat= AdvanceUndoNumber("finish cont groove")
        Stat= AddGroupToUndo(WsUBCreateMode,Path,1,WsTrue)
        Stat= AddItemToUndo(WsUBCreateMode,P1)
        Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
        Stat= PlotEntity(Contour)
        Stat= PlotEntity(Path)
        Stat= PlotEntity(P1)
        IF Animate_tool AND NOT ValidGeometry(P1) THEN
                 Work_trans= CurrentWorkplane
                 Stat= AnimateTool(Tool,Path)
        END IF
END IF
GOTO Pick_loop




Leave:!
PlotOn
Stat=SetCurrentColor(Current_pen)
IF ValidGeometry(Work) THEN Stat=SetWorkplane(Work)

IF NOT LEN(Destination$) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END

