
! script name: 3dcpaths.d/scutleadin
! 3dtopic: create lead in and out moves for a single cutterpath curve

!A
!A NAME:
!A
!A 	3D Modify: Add Cut Leadin/Leadout
!A
!A DESCRIPTION:
!A
!A 	This script creates lead in and lead out moves for a single curve in
!A 	a 3D Cutterpath.
!A
!B INSTRUCTIONS:
!B
!B 	PICK CURVE TO BE MODIFIED, Undo, Clear, Modify: Pick the curve to
!B 		be modified.
!B
!B 		U - Undo works in a recursive manner.
!B 		C - Clear means that the script will start over without
!B 		    modifying the curves, unless Modify has already been
!B 		    selected.
!B 		M - Modify finalizes the process.
!B

Stat=ChangeLabelStr("ScriptNameStatus","Function: cutterpath curve lead in and lead out ")

DIM Destination$[256]
DIM Answer$[256]
DIM Datastr$[1256]
DIM Boundary_name$[256]
REAL Leadintype
REAL Leadouttype
REAL cuts(0:500)

DeActivateUndo
Units=CurrentUnits

IF Units=WsMetric THEN
	Dist=12.5
	Radius=6.25
ELSE
	Dist=0.5
	Radius=0.25
END IF

LeadinVarsType=20011

Leadintype=NamedVarVal("leadin type",LeadinVarsType,1.0)
Leadouttype=NamedVarVal("leadout type",LeadinVarsType,1.0)
Leadindist=NamedVarVal("leadin dist",LeadinVarsType,Dist)
Leadoutdist=NamedVarVal("leadout dist",LeadinVarsType,leadindist)
Rin=NamedVarVal("leadin radius",LeadinVarsType,Radius)
Rout=NamedVarVal("leadout radius",LeadinVarsType,Radius)
Which_side=NamedVarVal("leadout side",LeadinVarsType,0)
! which_side used in 3d to control location of leadin 

Current_pen=CurrentColor
Highlight_color=2

Start:!
Ncuts=0

Ploop:!
Stat=SetInputFormat("a1",",M,U,C,")
E1=PickEntity("PICK CURVE TO BE MODIFIED, Undo, Clear, Modify ", Answer$)
IF ExitScript(Destination$) THEN Leave
SELECT Answer$
    CASE "M"
	GOTO Modify_cpaths
    CASE "U"
	Ncuts=Ncuts-1
	IF Ncuts<0 THEN Ncuts=0
	IF ValidGeometry(Cutterpath) THEN
		Pen1=GetColor(Cutterpath)
		Stat=PlotEntity(Cutterpath,pen1)
		Stat=HighlightCpath(Cutterpath,Cuts,Ncuts,Highlight_color)
	END IF
	GOTO Ploop
    CASE "C"
	IF ValidGeometry(Cutterpath) THEN
		Pen1=GetColor(Cutterpath)
		Stat=PlotEntity(Cutterpath,pen1)
	END IF
	GOTO Start
END SELECT
IF NOT ValidGeometry(E1) THEN Ploop

Etype=EntityType(E1)
IF Etype=WsCPathFileEnt THEN
	IF Ncuts=0 THEN Cutterpath=E1
	T=LastPickPara
	Path=INT(T)
	Cuts(Ncuts)=Path
	Ncuts=Ncuts+1
	Stat=HighlightCpath(Cutterpath,Cuts,Ncuts,Highlight_color)
END IF
GOTO Ploop

Modify_cpaths:!

Stat=SetCurrentColor(Pen_color)

Stat=CPathLeadInOut(Cutterpath,Rin,Leadindist,Leadintype,Rout,Leadoutdist,Leadouttype,Which_side,cuts,ncuts)

GOTO Start

Leave:!
Stat=SetCurrentColor(Current_pen)
Vleadintype=CreateVariable("leadin type",LeadinVarsType,leadintype)
Vleadouttype=CreateVariable("leadout type",LeadinVarsType,leadouttype)
Vleadin=CreateVariable("leadin dist",LeadinVarsType,leadindist)
Vleadout=CreateVariable("leadout dist",LeadinVarsType,leadoutdist)
VRout=CreateVariable("leadin radius",LeadinVarsType,Rin)
VRin=CreateVariable("leadout radius",LeadinVarsType,Rout)
Vside=CreateVariable("leadout side",LeadinVarsType,Which_side)
Stat=SetInputFormat("n4","")
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END
