
! script name: contours.d/sharpcorners
! topic: make small corner radii sharp.

!A
!A NAME:
!A
!A 	Makes Sharp Contour Corners
!A
!A DESCRIPTION:
!A
!A 	This script make small corner radii on a contour sharp.
!A
!B INSTRUCTIONS:
!B
!B 	PICK CONTOUR : Pick an element on the contour.
!B
!B 	MINIMUM RADIUS FOR SHARP CORNER: Input the
!B 		minimum radius to be used on corners. All radii
!B 		smaller than this amount will be made into sharp corners.
!B
!B 	REPLACE ORIGINAL CONTOUR Yes, No, Cancel:
!B
!B 		Y - for yes will replace the original contour with the new
!B 		    contour.
!B
!B 		N - for no will not delete the original but will keep the
!B 		    new contour.
!B 		C - for cancel will delete the new contour but leave
!B 		    the original unchanged.
!B
!C NOTES:
!C
!C 	This function will check each radius of a contour if the radius
!C 	is smaller than the Minimum it will make the radius to small
!C 	to be output on a CNC file.
!C
!C 	CAUTION: Do not use these contours for surfacing.
!C

stat=ChangeLabelStr("ScriptNameStatus","Function: sharp corners ")

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


ActivateUndo
Ploop:!
Stat= SetInputFormat("n4","")
Contour=PickGroupEnt("PICK CONTOUR",0)
IF (ExitScript(Destination$)) THEN Leave
Stat=Highlight(Contour,WsPickPen,WsDirArrowOff)

Radius= InputRadius("MINIMUM RADIUS FOR SHARP CORNERS")
IF (ExitScript(Destination$)) THEN Leave

New_contour=MinRadiusCorners(Contour,Radius,Radius,WsTrue)

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("sharp corners")
	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"
	Tool= GetAssocTool(Contour)
        IF ValidGeometry(Tool) THEN
                Stat= AssociateTool(New_contour,Tool)
        END IF
	stat= GroupName(Contour,Name$)
        Stat= AutoNumberCont(New_contour)
	stat= ChangeGrpName(New_contour,Name$)

	ActivateUndo
	Stat= AdvanceUndoNumber("sharp corners")
	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("sharp corners")
	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 Ploop

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