
! script name: contours.d/smoothcontour
! topic: smooths a contour

!A
!A NAME:
!A
!A 	Smooth Contour	
!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
!C NOTES:
!C
!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	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	Output circles will cause the curve to
!C	be generated with circle and line segments.
!C
!C	The original contour is deleted.
!C

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

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


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 ValidGeometry(Contour) THEN Pick_contour

New_contour=SmoothContour(Contour,Dist,Tol,Smooth,Circle_sw)

Stat= SetInputFormat("a1=",",Y,N,C,")
Stat= GetValue("REPLACE ORIGINAL CONTOUR Yes, No, Cancel",Answer$)
IF (ExitScript(Destination$)) THEN
        Tool= GetAssocTool(Contour)
        IF ValidGeometry(Tool) THEN
                Stat= AssociateTool(New_contour,Tool)
        END IF
        Stat= AutoNumberCont(New_contour)

        ActivateUndo
        Stat= AdvanceUndoNumber("smooth contour")
        Stat= AddGroupToUndo(WsUBCreateMode,New_contour,1,WsTrue)

        GOTO Leave
END IF

Pen_color= CurrentColor
Pen_color= Pen_color+ WsPickPen*(NOT Pen_color)
SELECT Answer$
CASE "Y"
        stat= GroupName(Contour,Name$)
        Tool= GetAssocTool(Contour)
        IF ValidGeometry(Tool) THEN
                Stat= AssociateTool(New_contour,Tool)
        END IF
        stat= ChangeGrpName(New_contour,Name$)

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

        stat= UnLink(Contour)
        stat= DeleteGroup(Contour,1)
        Stat=Highlight(New_contour,Pen_color,WsDirArrowOn)
CASE "N"
        Tool= GetAssocTool(Contour)
        IF ValidGeometry(Tool) THEN
                Stat= AssociateTool(New_contour,Tool)
        END IF
        Stat= AutoNumberCont(New_contour)

        ActivateUndo
        Stat= AdvanceUndoNumber("smooth contour")
        Stat= AddGroupToUndo(WsUBCreateMode,New_contour,1,WsTrue)

CASE "C"
        stat= UnLink(New_contour)
        stat= DeleteGroup(New_contour,1)
        Stat=Highlight(Contour,Pen_color,WsDirArrowOff)
END SELECT

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

