
! script name: voffset.d/helixcircir
! var_topic: path for a helix using two circles

!A
!A NAME:
!A
!A 	Mill Helix (Circle and Circle)		VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script creates a path using a helix.  It is defined
!A	by a top circle, a bottom circle, and a depth.  The top
!A	of the helix is defined by the start point and the bottom
!A	is controlled by the depth.  There is a helical leadin
!A	that is controlled by angular extent and z distance
!A	variables.
!A
!B INSTRUCTIONS:
!B
!B	DIAMETER AT THE TOP: Enter the starting diameter for the
!B		helix to be offset.  This is the diameter at the
!B		top of the hole or boss you are cutting.
!B
!B	DIAMETER AT THE BOTTOM: Enter the ending diameter for the
!B		helix to be offset.  This is the diameter at the
!B		bottom of the hole or boss you are cutting.
!B
!B 	HOLE DEPTH: Enter the distance from the top of the hole to
!B		the bottom of the hole as a positive number.
!B
!B 	DEPTH OF CUT: Enter the depth of cut. This helps
!B		determine the number of revolutions.
!B
!B 	CENTER POINT: Enter the center location.  This indicates the
!B		the X,Y center of the helix and the top starting location.
!B
!B NOTE:
!B	The spiral radii are calculated from the tangency of the
!B	taper and the corner radius (if any) of the tool.
!B
!B	A leadin angle of 0 will leave off the helical leadin to the
!B	start of the hole.  There are no leadins on upward cuts.
!B
!B	The finish allowance is subtracted from the radii of
!B	the circles.  It is not the perpendicular along the wall.
!B	Therefore, the allowance left will be slightly larger
!B	than the value given.
!B	The bottom allowance affects the depth of the hole.
!B
!B	The cleanup pass adds a circle(s) to the end of the helix.
!B	There are no cleanup passes on upward cuts.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: helix mill circle-circle ")

DIM Answer$[256]
DIM Destination$[256]
DIM Name$[256]
DIM Center$[256]
DIM Destination$[256]
DIM Sdia_var$[256],Edia_var$[256]
DIM Doc_var$[256]
DIM Depth_var$[256]
DIM Tool_name$[256]
DIM Tool_image$[256]
DIM Toolid$[256]
DEG

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

Astart= 0
Diar= 2
Depthr= 1
IF CurrentUnits= WsMetric THEN
	Docr= 1
ELSE
	Docr= .03
END IF

IF ARGC>1 THEN
	Answer$= ARGV(1)
	GOTO Have_tool
END IF

ActivateUndo
Start:!
Stat=SetInputFormat("n4","")

Stat=ToolSelectBox("TOOLS","selected tool",WsAllMills)
IF Stat THEN 
  LOAD "vtools.d/readmilltool:voffset.d/helixcircir"
  Stat= MessageFileBox("/usr/weber/database/messages/notoolsloaded","ATTENTION")
  GOTO Leave
END IF
Tool_ques:!
Stat=SetInputFormat("a99","")
Stat=GetValue("PATH TOOL, New_tool ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$= "CANCEL" THEN
	LowerSelectBox
	GOTO Leave
END IF
IF Answer$="New_tool" THEN
	LowerSelectBox
	LOAD "vtools.d/readmilltool:voffset.d/helixcircir"
END IF

Have_tool:!
Tool_name$= Answer$

Start_dia:!
Stat=SetInputFormat("n4=","")
Stat=SetRadiusEquals(Diar/2)
Start_dia=InputRadius("DIAMETER AT THE TOP",WsDiaInput)
IF (ExitScript(Destination$)) THEN Leave
No_sdia_var= LastVariableInput(Sdia_var$)
Diar= Start_dia
C1= LastPickEnt
IF 0 AND ValidGeometry(C1) THEN
        IF NOT ValidDependency(C1) THEN Start_dia
        Stat= EntityNameCheck(C1,Sdia_var$)
	No_sdia_var= 0
END IF

End_dia:!
Stat=SetInputFormat("n4=","")
Stat=SetRadiusEquals(Diar/2)
End_dia=InputRadius("DIAMETER AT THE BOTTOM",WsDiaInput)
IF (ExitScript(Destination$)) THEN Leave
No_edia_var= LastVariableInput(Edia_var$)
C2= LastPickEnt
IF 0 AND ValidGeometry(C2) THEN
        IF NOT ValidDependency(C2) THEN End_dia
        Stat= EntityNameCheck(C2,Edia_var$)
	No_edia_var= 0
END IF

Hole_depth:!
IF ValidGeometry(C1) AND ValidGeometry(C2) THEN
	P1= CircleCenter(C1)
	P2= CircleCenter(C2)
	Hole_depth= ABS(DistTwoPts(P1,P2))
	Stat= DeleteEntityList(P1,P2)
	IF Hole_depth<= 0.001 THEN Hole_depth2
	No_depth_var= 1
ELSE
Hole_depth2:!
	Hole_depth= InputDepth("HOLE DEPTH")
	IF (ExitScript(Destination$)) THEN Leave
	No_depth_var= LastVariableInput(Depth_var$)
	Depthr= Hole_depth
END IF

Stat= SetEqualsValue(Docr)
Depth_of_cut=GetValue("DEPTH OF CUT",Answer$)
IF (ExitScript(Destination$)) THEN Leave
No_doc_var= LastVariableInput(Doc_var$)
Docr= Depth_of_cut

Leadin_dist= Depth_of_cut

Pick_point:Stat=SetInputFormat("n4a1",",C,N,")
E1=PickEntity("CENTER POINT, Change_tool, New_hole ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$="C" THEN Start
IF Answer$="N" THEN Start_dia
!IF NOT ValidGeometry(E1) THEN Pick_point
!IF NOT ValidDependency(E1) THEN Pick_point
Pick_para= LastPickPara
Pick_return= CurrPickReturn
Stat= EntityNameCheck(E1,Center$)

IF Start_dia>=End_dia THEN
	In_out= 1
ELSE
	In_out= -1
END IF

Stat= GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("HELICAL MILL: Mill circle circle "&Tool_name$)
Stat= SetRecDelLastExec
SELECT Pick_return
CASE WsGeometryEnd
        Pc= ParameterReturnPt(Center$,Pick_para,WsGeometryEnd)
CASE WsGeometryMid
        Pc= ParameterReturnPt(Center$,Pick_para,WsGeometryMid)
CASE WsGeomCenter
        Pc= ParameterReturnPt(Center$,Pick_para,WsGeomCenter)
END SELECT
IF No_sdia_var THEN
	V1= FreeParameter("Start diameter",Start_dia)
ELSE
        V1= FreeParameter("Start diameter",Sdia_var$)
END IF
IF No_edia_var THEN
	V2= FreeParameter("End diameter",End_dia)
ELSE
        V2= FreeParameter("End diameter",Edia_var$)
END IF
IF No_depth_var THEN
	V3= FreeParameter("Hole depth",Hole_depth)
ELSE
        V3= FreeParameter("Hole depth",Depth_var$)
END IF
IF No_doc_var THEN
        V4= FreeParameter("Depth of cut",Depth_of_cut)
ELSE
        V4= FreeParameter("Depth of cut",Doc_var$)
END IF
V5= FreeParameter("Start angle",Astart)
V6= FreeParameter("Finish allowance",0)
V7= FreeParameter("Bottom allowance",0)
V8= FreeParameter("Leadin clearance",Depth_of_cut)
V9= FreeParameter("Leadin angle",90)
V10= FreeParameter("( -1 )Climb or ( 1 )Conventional",-1)
V11= FreeParameter("( 1 )Inside or ( -1 )Outside",In_out)
V12= FreeParameter("( 1 )Down or ( -1 )Up",1)
V13= FreeParameter("Cleanup passes",1)
Tool=FindUserData(Tool_name$,WsToolData)
Mdef1= ToolMillingDef(Tool,V10)
Stat= MillDefCutInfo(Mdef1,V11,0,V6,0,1)
Stat= MillDefZInfo(Mdef1,1,V3,V4,V7)
Path= MillHelixCirCir(Pc,Mdef1,V1,V2,V5,V8,V9,V12,V13)
Stat= AutoNameGroup(Path,Name$)
Stat= AssociateTool(Path,Tool)
Stat= DeleteEntity(Pc)
RecordFunctionOff
ActivateUndo
CloseVarRecord

IF NOT ValidGeometry(Path) THEN
        DelLastVarRecord
ELSE
        Stat= AnimateTool(Tool,Path)
        ActivateUndo
        Stat= AdvanceUndoNumber("mill helix")
        Stat= AddGroupToUndo(WsUBCreateMode,Path,1,WsTrue)
        Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF

GOTO Pick_point

Leave:!
Stat=SetPickReturn(WsGeometryEnd)
Stat=SetInputFormat("n4","")
Stat= DeleteEntityList(Pc,P1,P2,P3)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END

