
! script name: v3dcpath.d/smoothcpathcut
! var_topic: smooths a cutterpath cut

!A
!A NAME:
!A
!A 	Smooth 3D Cutterpath		VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will smooth a 3D Cutterpath Cut.
!A
!B INSTRUCTIONS:
!B
!B 	PICK CUTTERPATH TO BE CHANGED: Pick the cutter path to be changed.
!B
!C NOTES:
!C
!C 	The smoothed curve will deviate from the original cutterpath.
!C 	The deviation may be enough to cause gouging. There is no
!C 	check for this in this function.
!C
!C 	The free parameter Smooth will determine the method of smoothing
!C 	A value of Smooth=1 will use a cubic nurb curve. A value of
!C 	Smooth=2 will use a bezier curve.
!C
!C 	The free parameter Distance will control the number of extra
!C 	points generated for the nurb curves. A small distance will
!C 	cause more points to be generated thus causing the smoothed
!C 	curve to be closer to the contour.
!C
!C 	The free parameter Output circles will cause the curve to
!C 	be generated with circle and line segments.
!C

Stat=ChangeLabelStr("ScriptNameStatus","Function: smooth 3d cutterpath")

DIM Destination$[256]
DIM Answer$[256]
DIM Cpath_name$[256]

Var_object=CheckVarObject
IF ExitScript(Destination$) THEN Leave

DeActivateUndo
Tol=NamedVarVal("3D Cutting Tol",Ws3DSystemVars,0.005)
Dist=NamedVarVal("smoothing distance",WsSystemVars,100*Tol)
Circle_sw=1
Smooth= 1


Pick_loop:Cpath=PickEntity("PICK CUTTERPATH")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(Cpath) THEN Pick_loop
Stat= EntityNameCheck(Cpath,Cpath_name$)
Etype=EntityType(Cpath)
IF Etype<>WsCPathFileEnt THEN Pick_loop
T= LastPickPara
Path= INT(T)


Stat=EraseEntity(Cpath)
RecordFunctionOn
Stat=RecordDescr("3D CUTTERPATH: Smooth")
V1=FreeParameter("Distance",Dist)
V2=FreeParameter("Tolerance",Tol)
V3=FreeParameter("Smooth",Smooth)
V4=FreeParameter("Circle output",Circle_sw)
V5=FreeParameter("Path number",Path)
Stat=SmoothCpath(Cpath_name$,V1,V2,V3,V4,V5)
RecordFunctionOff
CloseVarRecord
Stat=PlotEntity(Cpath)

GOTO Pick_loop

Leave:!
V1=CreateVariable("smoothing distance",WsSystemVars,Dist)
Stat=SetInputFormat("n4","")
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END

