
! script name: pkvmach.d/vpkrotaryparallel
! solids: rotary parallel gouge check

!A
!A NAME:
!A
!A 	Gouge Check: Rotary Parallel
!A
!A DESCRIPTION:
!A
!A	This function uses the same cutting technique as the parallel
!A	gouge check but applied to rotary axis cutting. The body is
!A	rotated to an angle then the cutter is locked in a vertical plane.
!A
!A
!B INSTRUCTIONS:
!B
!B 	FINISH ALLOWANCE: Enter the amount of material to be left for a
!B 		finish pass.
!B
!B      TOLERANCE: Enter the amount of variation allowed.
!B
!B      ROTARY AXIS: X, Y, Z: Select the rotary axis.
!B
!B	TOOL TILT ANGLE: Give the tilt of the tool from the vertical
!B			 position. A non-zero tilt will result in a
!B			 five axis cut.
!B
!B	START ANGLE: Give the starting angle.
!B
!B	ANGULAR EXTENT: Give the angular extent of the cut.
!B
!B	ANGULAR STEP: Give the angular increment between cuts.
!B
!B      START LENGTH: Give the starting length of the cuts along the axis.
!B
!B      END LENGTH: Give the ending length of the cuts along the axis.
!B
!B      START WIDTH: Give the starting width perpendicular to the axis.
!B
!B      END WIDTH: Give the ending width perpendicular to the axis.
!B
!B	Z BOTTOM: Give the lowest z level for the cut to penetrate.
!B
!B      PICK BODY TO BE MACHINED: Pick the body. It may be a sheet or solid.
!B				  A group of faces may be selected instead of
!B				  a body. This group will be treated as if it
!B				  were a free standing sheet body.
!B
!B      WIDTH OF CUT: Enter the actual width of cut.
!B
!B      PICK ADDITIONAL SURFACE GROUP, Name, Proceed   Additional synergy
!B      surfaces may be added here to the body to be machined.
!B      There surfaces may be used to keep the cutter out of
!B      areas of the body or to to extend parts of the body for machining.
!B
!B
!C NOTES:
!C
!C	By default the cuts will zigzag. This may be changed by editing
!C	a parameter or by changing the system variable for zigzag cuts.
!C
!C
!C


Stat=ChangeLabelStr("ScriptNameStatus","Function: rotary parallel gouge check ")

DIM Destination$[256]
DIM Answer$[256]
DIM Tool_name$[256]
DIM Body_name$[256]
DIM Tool_type$[256]
DIM Toolid$[256]
DIM Part_group$[256]
DIM Finish_var$[256]
DIM Astart_var$[256]
DIM Angle_var$[256]
DIM Astep_var$[256]
DIM Width_var$[256]
DIM Slen_var$[256]
DIM Elen_var$[256]
DIM Swid_var$[256]
DIM Ewid_var$[256]
DIM Zbot_var$[256]
DIM Tilt_var$[256]
DIM Name$[256]

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

ActivateUndo
Tol=NamedVarVal("3D Cutting Tol",Ws3DSystemVars,0.005)
Zigzag_cuts=NamedVarVal("3D Zigzag Cuts",Ws3DSystemVars,1.0)
Zaddon=NamedVarVal("Z Cutter Displacement",Ws3DSystemVars,0.0)
Units=CurrentUnits

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

Start:!
Past_dia:!
Stat=UserSelectBox("TOOLS","selected tool",WsToolData,WsUserSelect)
IF Stat THEN 
  LOAD "vtools.d/readmilltool:pkvmach.d/vpkrotaryparallel"
  Stat= MessageFileBox("/usr/weber/database/messages/notoolsloaded","ATTENTION")
  GOTO Leave
END IF
Tool_ques:!
Stat=SetInputFormat("a99","")
Stat=GetValue("CUTTER PATH TOOL, New_tool ",Tool_name$)
IF ExitScript(Destination$) THEN Leave
IF Tool_name$= "CANCEL" THEN Leave
LowerSelectBox
IF Tool_name$="New_tool" THEN
	LOAD "vtools.d/readmilltool:pkvmach.d/vpkrotaryparallel"
END IF
Have_tool:!
Tool=FindUserData(Tool_name$,WsToolData)
Stat=GetUserString(Tool,"Tool type:",Toolid$)
IF NOT POS(Toolid$, "MILL") THEN Tool_ques



Past_dia:!
Finishr=NamedVarVal("finish allowance",WsSystemVars,0.0)
Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Finishr)
Finish_allow=GetValue("FINISH ALLOWANCE",Answer$)
IF ExitScript(Destination$) THEN Leave
Finishr=Finish_allow
No_finish_var= LastVariableInput(Finish_var$)

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Tol)
Tol=GetValue("TOLERANCE",Answer$)
IF ExitScript(Destination$) THEN Leave

Vfinish=CreateVariable("finish allowance",WsSystemVars,Finishr)

Rotary_axis:Stat=SetInputFormat("a1=",",X,Y,Z,")
Stat=SetEqualsValue(0,"Y")
Stat=GetValue("ROTARY AXIS: X, Y, Z ",Answer$)
IF ExitScript(Destination$) THEN Leave
SELECT Answer$
CASE "X"
        Axis_number=1
CASE "Y"
        Axis_number=2
CASE "Z"
        Axis_number=3
CASE ELSE
        GOTO Rotary_axis
END SELECT

Stat=SetInputFormat("n4=","")
Stat=SetAngleEquals(0)
Tilt_angle=InputAngle("TOOL TILT ANGLE")
IF ExitScript(Destination$) THEN Leave
No_tilt_var= LastVariableInput(Tilt_var$)


Stat=SetInputFormat("n4=","")
Stat=SetAngleEquals(Astart)
Astart=InputAngle("START ANGLE")
IF ExitScript(Destination$) THEN Leave
No_astart_var= LastVariableInput(Astart_var$)

Stat=SetInputFormat("n4=","")
Stat=SetAngleEquals(360)
Angle=InputAngle("ANGULAR EXTENT")
IF ExitScript(Destination$) THEN Leave
No_angle_var= LastVariableInput(Angle_var$)

Stat=SetInputFormat("n4=","")
Stat=SetAngleEquals(5)
Astep=InputAngle("ANGULAR STEP")
IF ExitScript(Destination$) THEN Leave
No_astep_var= LastVariableInput(Astep_var$)

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(start_length)
start_length=GetValue("START LENGTH",Answer$)
IF ExitScript(Destination$) THEN Leave
No_slen_var= LastVariableInput(Slen_var$)

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(end_length)
end_length=GetValue("END LENGTH",Answer$)
IF ExitScript(Destination$) THEN Leave
No_elen_var= LastVariableInput(Elen_var$)

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(start_width)
start_width=GetValue("START WIDTH",Answer$)
IF ExitScript(Destination$) THEN Leave
No_swid_var= LastVariableInput(Swid_var$)

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(end_width)
end_width=GetValue("END WIDTH",Answer$)
IF ExitScript(Destination$) THEN Leave
No_ewid_var= LastVariableInput(Ewid_var$)

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Z_bottom)
Z_bottom=GetValue("Z BOTTOM",Answer$)
IF ExitScript(Destination$) THEN Leave
No_zbot_var= LastVariableInput(Zbot_var$)

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Widthr)
Width_cut=GetValue("WIDTH OF CUT",Answer$)
IF ExitScript(Destination$) THEN Leave
Width_cut=ABS(Width_cut)
Widthr=Width_cut
No_width_var= LastVariableInput(Width_var$)
Vwidth=CreateVariable("width of cut",WsSystemVars,Widthr)

Pick_loop:!
Stat=SetInputFormat("a1",",F,A,")
E1=WPKPickEntity("PICK BODY  Face group, Assembly ",WsPKPickAll,Answer$)
IF (ExitScript(Destination$)) THEN Leave
SELECT Answer$
CASE "A"
	Pkassembly= WPKCurrentAssembly
	IF NOT WPKIsEntity(Pkassembly) THEN
       		 Stat=SetInputFormat("n4","")
       		 E1=WPKPickEntity("PICK ASSEMBLY")
       		 IF (ExitScript(Destination$)) THEN Leave
       		 IF NOT WPKIsEntity(E1) THEN pick_loop

       		 Pkbody= WPKParentBody(E1)
       		 Pkassembly= WPKParentAssembly(Pkbody)
	END IF
	IF NOT WPKIsEntity(Pkassembly) THEN Pick_loop
        Stat= EntityNameCheck(Pkassembly,Body_name$)
CASE "F"
	Stat=SetInputFormat("n4","")
	E1=WPKPickEntity("PICK GROUP TO BE MACHINED")
	IF (ExitScript(Destination$)) THEN Leave
	IF NOT WPKIsEntity(E1) THEN Pick_loop
	G1= WPKContainingGroup(E1,1,WsTrue)
	IF NOT WPKIsEntity(G1) THEN Pick_loop
	Stat= EntityNameCheck(G1,Body_name$)
CASE ELSE
	IF NOT WPKIsEntity(E1) THEN Pick_loop
	Body_ent= WPKParentBody(E1)
	Stat= EntityNameCheck(Body_ent,Body_name$)
END SELECT

Stat=SetPickMask(WsPickSurfOnly)
Stat=SetInputFormat("n4a1",",N,P,")
Part_group=PickGroupEnt("PICK ADDITIONAL SURFACE GROUP, Name, Proceed ",WsSurfaceGroup,Answer$)
IF ExitScript(Destination$) THEN Leave
SELECT Answer$
CASE "N"
        GOSUB Get_named_group
CASE "P"
        Extra_surfs=0
        GOTO Cut_part
END SELECT
IF NOT ValidDependency(Part_group) THEN Pick_loop
Stat= EntityNameCheck(Part_group,Part_group$)
Stat=Highlight(Part_group,WsPickPen,WsDirArrowOff)
Extra_surfs=1


Cut_part:!
Start_variation:!

Stat= GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("CUTTERPATH: Rotary Parallel Cuts")
Stat= SetRecDelLastExec
RecordFunctionOn
Work1= CurrentWorkplane
Stat= SetWorkplane(0)
V15= FreeParameter("Axis number",Axis_number)
Base_pt= PointXYZ(0,0,0)
Axis_pt= StdRotaryAxis(V15)
Orient_pt= StdRotaryOrientPt(V15)

IF No_finish_var THEN
        V1= FreeParameter("Finish allowance",Finish_allow)
ELSE
        V1= FreeParameter("Finish allowance",Finish_var$)
END IF
V2= FreeParameter("Tolerance",Tol)
IF No_slen_var THEN
        V3= FreeParameter("Start length",Start_length)
ELSE
        V3= FreeParameter("Start length",Slen_var$)
END IF
IF No_elen_var THEN
        V4= FreeParameter("End length",End_length)
ELSE
        V4= FreeParameter("End length",Elen_var$)
END IF

IF No_swid_var THEN
        V5= FreeParameter("Start width",Start_width)
ELSE
        V5= FreeParameter("Start width",Swid_var$)
END IF
IF No_ewid_var THEN
        V6= FreeParameter("End width",End_width)
ELSE
        V6= FreeParameter("End width",Ewid_var$)
END IF
IF No_width_var THEN
        V7= FreeParameter("Width cut",Width_cut)
ELSE
        V7= FreeParameter("Width cut",Width_var$)
END IF
IF No_astart_var THEN
        V8= FreeParameter("Astart",Astart)
ELSE
        V8= FreeParameter("Astart",Astart_var$)
END IF
IF No_angle_var THEN
        V9= FreeParameter("Angle",Angle)
ELSE
        V9= FreeParameter("Angle",Angle_var$)
END IF
IF No_astep_var THEN
        V10= FreeParameter("Angle step",Astep)
ELSE
        V10= FreeParameter("Angle step",Astep_var$)
END IF
IF No_tilt_var THEN
        V11= FreeParameter("Tool tilt",Tilt_angle)
ELSE
        V11= FreeParameter("Tool tilt",Tilt_var$)
END IF
IF No_zbot_var THEN
        V12= FreeParameter("Z bottom",Z_bottom)
ELSE
        V12= FreeParameter("Z bottom",Zbot_var$)
END IF
V13= FreeParameter("Zigzag cuts",Zigzag_cuts)
Tool=FindUserData(Tool_name$,WsToolData)
Mdef1= ToolMillingDef(Tool,Mill_dir)
Stat=AssociateTool(Mdef1,Tool)
Stat= MillDefCutInfo(Mdef1,1,0.0,V1)
Stat=Setup3dCutter(Mdef1)
PlotOff
Stat= PrintToVarRecord("PlotOff")
Body_group= WPKConvertBody(Body_name$,WsPKConvertFaces)
Stat= SetEdgeExt(Body_group)
Stat= HideEntity(Body_group)
Stat= SetWorkplane(Work1)
RecordFunctionOff
IF Extra_surfs THEN
RecordFunctionOn
        Part= CopyEntity(Part_group$)
        Stat= CombineGroups(Part,Body_group)
RecordFunctionOff
ELSE
RecordFunctionOn
        Part= CopyEntity(Body_group)
RecordFunctionOff
END IF
RecordFunctionOn
Stat= PrintToVarRecord("PlotOn")
PlotOn
Cpath_group=RotaryParallelCuts(Part,Base_pt,Axis_pt,Orient_pt,V11,V3,V4,V5,V6,V12,V7,V8,V9,V10,V2,V13)
Stat= PrintToVarRecord("PlotOff")
Stat= AutoNameGroup(Cpath_group,Name$)
Stat=AssociateTool(Cpath_group,Tool)
Stat= DeleteGroup(Body_group,WsTrue)
Stat= DeleteEntitylist(Part,Mdef1,Base_pt,Axis_pt,Orient_pt)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(Cpath_group) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("rotary parallel cuts")
	Stat= AddGroupToUndo(WsUBCreateMode,Cpath_group,1,WsTrue)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
Stat= DeleteEntity(Group)
GOTO Pick_loop


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


Get_named_group:!
Stat=ListGrpNames("SURFACE GROUPS","selected group","",WsSurfaceGroup)
IF Stat=1 THEN Leave_name

Stat=SetInputFormat("a99","")
Stat=GetValue("SURFACE GROUP NAME",Answer$)

IF (ExitScript(Destination$)) THEN Leave
IF Answer$="CANCEL" THEN Leave_name
Part_group=FindNamedGrp(Answer$)
IF NOT ValidGeometry(Part_group) THEN Get_named_group
Grp_type= GroupType(Part_group)
IF Grp_type <> WsSurfaceGroup THEN Get_named_group
LowerSelectBox

Leave_name:!
Stat=SetInputFormat("n4","")

RETURN


END
