
! script name: offsets.d/wireoffset
! topic: wire offset with minimum look ahead

!A
!A NAME:
!A
!A 	Minimum: Wire Offset - minimum look ahead
!A
!A DESCRIPTION:
!A
!A 	This script generates a cutter path with a minimum look ahead.
!A 	The LOOK AHEAD's function is to find where PATH elements are
!A 	eliminated, and then to determine whether that part must be
!A 	aborted, or can continue past the eliminated element.  The
!A 	MINIMUM look ahead looks ahead three elements, and is suitable
!A 	for most contours.  It performs three calculations for each
!A 	PATH element.  If the path is unacceptable, e.g., crosses over
!A 	itself, or stops short of completion, redo the path with a full
!A 	look ahead.
!A
!B INSTRUCTIONS:
!B
!B 	KERF OFFSET: Enter the offset of the wire to be used.
!B
!B 	PICK AN ELEMENT OF CONTOUR TO BE OFFSET: Pick an element on
!B 		the contour to be offset.
!B
!B 	PICK WHICH SIDE: Pick which side of the contour the path should
!B 		be generated.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: wire offset ")

DIM Destination$[256]
DIM Answer$[256]
DIM Datastr$[1256]
DIM Boundary_name$[256]
DIM Tool_name$[256]

Current_pen=CurrentColor

ActivateUndo
GOSUB Get_kerf_dia

Fin_allow:!
Vcutter=CreateVariable("cutter diameter",WsSystemVars,Cutter_dia)

Pick_loop:!

Offset= Kerf_offset

Stat=SetPickMask(WsPickNoSurf)
Contour=PickEntity("PICK AN ELEMENT OF CONTOUR TO BE OFFSET")
IF (ExitScript(Destination$)) THEN Leave


Pt=InputFreePoint("PICK WHICH SIDE")
IF (ExitScript(Destination$)) THEN Leave

Side=OffsetLeftRight(Contour,Pt)
Stat=Highlight(Contour,WsPickPen,WsDirArrowOff)

Dist=-Side*Offset
Pen_color= 10*(Dist>=0)+ 11*(Dist<0)

Direction=WsForward

Stat=SetCurrentColor(Pen_color)
Path=OffsetContour(Contour,Dist,Direction,WsMinLook,WsCircleMoves,Pen_color,WsDirArrowOn)

ActivateUndo
Stat= AdvanceUndoNumber("wire offset")
Stat= AddGroupToUndo(WsUBCreateMode,Path,1,WsTrue)

Stat=DeleteEntity(Pt)

GOTO Pick_loop

Get_kerf_dia:!
	Stat=SetInputFormat("n4=","")
	Stat=SetRadiusEquals(Kerf_offset)
	Kerf_offset=GetValue("KERF OFFSET")
	IF (ExitScript(Destination$)) THEN Leave
	Kerf_offset= ABS(Kerf_offset)
RETURN

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