
! script name: voffsets.d/offsetcontour
! var_topic: offset a contour

!A
!A NAME:
!A
!A 	Offset Contour		VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script generates an offset to a contour. The resulting geometry
!A	is a new contour.
!A
!A~ image location - images/offsetcontour.jpg
!B INSTRUCTIONS:
!B
!B 	OFFSET: Enter the offset to be used.
!B
!B 	PICK AN ELEMENT OF CONTOUR TO BE OFFSET: Pick
!B 		an element on the contour to be offset.
!B
!B 	PICK WHICH SIDE: Pick which side of
!B 		the contour the path should be generated.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: offsetcontour")

DIM Destination$[256]
DIM Answer$[256]
DIM Contour$[256]
DIM Offset_var$[256]
DIM Name$[256]


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


ActivateUndo
Pen_color= CurrentColor

Offset_dist:!
Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Offset_dist)
Offset=GetValue("OFFSET (+ right, - left)",Answer$)
IF (ExitScript(Destination$)) THEN Leave
No_offset_var= LastVariableInput(Offset_var$)


Pick_loop:!
Stat=SetPickMask(WsPickNoSurf)
E1=PickEntity("PICK AN ELEMENT OF CONTOUR TO BE OFFSET")
IF (ExitScript(Destination$)) THEN Leave
Contour= ParentGroup(E1,0)
IF NOT ValidDependency(Contour) THEN Pick_loop
Stat= EntityNameCheck(Contour,Contour$)

Direction=WsForward


Stat= GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("PATH: Offset")
Stat= SetRecDelLastExec
Stat= NullReference(Contour$)
IF No_offset_var THEN
	V1= FreeParameter("Offset",Offset)
ELSE
	V1= FreeParameter("Offset",Offset_var$)
END IF
V2= FreeParameter("Direction ",Direction)
E1= GroupElement(Contour$,1)
Path=OffsetContour(E1,V1,V2,WsFullLook,WsCircleMoves,Pen_color,WsDirArrowOn)
Stat= AutoNameGroup(Path,Name$)
Stat= SetNoPathFlag(Path,WsTrue)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(Path)  THEN
	DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("offset contour")
	Stat= AddGroupToUndo(WsUBCreateMode,Path,1,WsTrue)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
Stat= PlotEntity(Path)


GOTO Offset_dist

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