
! script name: vcontours.d/smoothcontour
! var_topic: smooths a contour

!A
!A NAME:
!A
!A 	Smooth Contour		VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script wil smooth a contour.
!A
!B INSTRUCTIONS:
!B
!B 	PICK CONTOUR TO BE CHANGED: Pick an element on the contour to be
!B 		changed.
!B
!B
!C NOTES:
!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 fro 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
!C	The original contour is deleted.

Stat=ChangeLabelStr("ScriptNameStatus","Function: smooth contour")

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

Var_object=CheckVarObject
IF ExitScript(Destination$) THEN Leave

ActivateUndo

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


Pick_contour:!
Contour=PickGroupEnt("PICK CONTOUR TO BE CHANGED")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(Contour) THEN Pick_contour
Stat=EntityNameCheck(Contour,Contour$)
IF NOT IsEntVariational(Contour) THEN
   Stat=SetInputFormat("a1",",Y,N,")
   Stat= GetValue("NON-VDM ENTITY. LOAD NON-VDM? Yes or No ",Answer$)
   IF Answer$="N" THEN Pick_contour
   Destination$= "contours.d/smoothcontour"
   Stat=SetInputFormat("n4","")
   GOTO Leave
END IF


Stat=GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat=RecordDescr("CONTOUR: Smooth")
V1=FreeParameter("Distance",Dist)
V2=FreeParameter("Tolerance",Tol)
V3=FreeParameter("Smooth",Smooth)
V4=FreeParameter("Circle output",Circle_sw)
C1=SmoothContour(Contour$,V1,V2,V3,V4)
RecordFunctionOff
IF ValidGeometry(C1) THEN
	RecordFunctionOn
	Stat=AutoNameGroup(C1,Name$)
	Tool= GetAssocTool(Contour$)

	ActivateUndo
	Stat= AdvanceUndoNumber("smooth contour")
	Stat= AddGroupToUndo(WsUBDeleteMode,Contour$,1,WsTrue)

	Stat=DeleteGroup(Contour$,WsTrue)
	Stat=AssociateTool(C1,Tool)
	RecordFunctionOff
	Stat=PlotEntity(C1)
END IF
RecordFunctionOn
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(C1) THEN
	DelLastVarRecord
ELSE
	Stat= AddGroupToUndo(WsUBCreateMode,C1,1,WsTrue)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF

GOTO Pick_contour

Leave:!

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

