
! script name: v3dwrap.d/polarwrapcont
! var_topic: polar wrap contour

!A
!A NAME:
!A
!A 	Polar Wrap Contour VARIATIONAL
!A
!A DESCRIPTION:
!A
!A	To be used on mill-turn machine tools.
!A	Interpolate a contour on the face of a rotary part. 	
!A
!A INSTRUCTIONS:
!A
!A	The routine does the following:
!A
!A		1) The contour must be parallel to the YZ plane.
!A		2) The current workplane must be in the plane of the contour.
!A		3) The contour is then interpolated to generate the 
!A		   C axis moves required to machine the contour.
!A		4) The original contour is deleted.
!A
!B
!B 	PICK CONTOUR: Pick the contour to be converted.
!B

Stat=ChangeLabelStr("ScriptNameStatus","Function: polar wrap contour ")

DIM Destination$[256]
DIM Answer$[256]
DIM Contour$[256]
DIM Tool_name$[256]
DIM Tool_image$[256]

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

ActivateUndo
Tol=NamedVarVal("3D Intersect Tol",Ws3DSystemVars,0.005)

Stat=ToolSelectBox("TOOLS","selected tool",WsAllMills)
IF Stat THEN 
  Stat= MessageFileBox("/usr/weber/database/messages/notoolsloaded","ATTENTION")
  GOTO Leave
END IF
Tool_ques:!
Stat=SetInputFormat("a99","")
Stat=GetValue("SELECT TOOL",Tool_name$)
IF ExitScript(Destination$) THEN Leave
IF Tool_name$= "CANCEL" THEN Leave
Tool=FindUserData(Tool_name$,WsToolData)
LowerSelectBox

Ploop:!

Stat=SetPickMask(WsPickNoSurf)
Stat=SetInputFormat("n4","")
Contour=PickGroupEnt("PICK CONTOUR ",0)
IF ExitScript(Destination$) THEN Leave
Stat=SetPickMask(WsPickAll)
IF NOT ValidDependency(Contour) THEN Ploop
Stat= EntityNameCheck(Contour,Contour$)


Stat= GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("CUTTERPATH: Polar Wrap Curve")
Stat= SetRecDelLastExec
Work= CurrentWorkplane
Stat= SetWorkplane
Center=PointXYZ(0,0,0)
Axis=PointXYZ(1.0,0,0)
Orient=PointXYZ(0,0,1)
V1= FreeParameter("Tolerance",Tol)
Tool=FindUserData(Tool_name$,WsToolData)
G1=PolarWrapContour(Contour$,Center,Axis,Orient,V1)
Stat=AssociateTool(G1,Tool)
Stat= AutoNameGroup(G1,Name$)
Stat= SetNoPathFlag(G1,WsTrue)
Stat= DeleteGroup(Contour$,WsTrue,WsTrue)
Stat= DeleteEntityList(Center,Axis,Orient)
Stat= SetWorkplane(Work)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(G1) THEN
        DelLastVarRecord
	Curr_record= 0
ELSE
        Stat= AnimateTool(Tool,G1)
	ActivateUndo
	Stat= AdvanceUndoNumber("polar wrap curve")
	Stat= AddGroupToUndo(WsUBCreateMode,G1,1,WsTrue)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
GOTO Ploop

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