
! script name: contours.d/mincornerrad
! topic: minimum radii on contour corners

!A
!A NAME:
!A
!A 	Minimum Radii
!A
!A DESCRIPTION:
!A
!A 	This script automatically checks for minimum radii on
!A 	contour corners.
!A
!B INSTRUCTIONS:
!B
!B 	PICK CONTOUR : Pick an element on the contour.
!B
!B 	MINIMUM RADIUS FOR CW CORNERS: Input the
!B 		minimum radius to be used on corners
!B 		traversed in a clockwise fashion.
!B
!B 	MINIMUM RADIUS FOR CCW CORNERS: Input the
!B 		minimum radius to be used on corners
!B 		traversed in a counterclockwise fashion.
!B
!B 	REPLACE ORIGINAL CONTOUR Yes, No, Cancel:
!B
!B 		Y - for yes will replace the original contour with
!B 		    the new contour.
!B 		N - for no will not delete the original but will
!B 		    keep the 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 and see if
!C 	it satisfies the minimum radii conditions. If a radius does
!C 	not satisfy the minimum conditions, the corner will be regenerated
!C 	with the appropriate minimum radius. It is assumed that this
!C 	minimum radius will fit.
!C
!C 	This function will attempt to fillet any sharp corner it sees on a
!C 	contour. The function assumes that the fillet radius
!C 	will fit into the elements without eliminating elements.
!C 	If the fillet does not fit then either no corner will be generated
!C 	or the corner radius will be generated incorrectly.
!C 	It is the operator's responsibility to verify that the
!C 	newly created contour is a valid contour.
!C

stat=ChangeLabelStr("ScriptNameStatus","Function: minimum corner radii")

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)

R1= InputRadius("MINIMUM RADIUS FOR CW CORNERS")
IF (ExitScript(Destination$)) THEN Leave

R2= InputRadius("MINIMUM RADIUS FOR CCW CORNERS")
IF (ExitScript(Destination$)) THEN Leave

New_contour=MinRadiusCorners(Contour,R1,R2)

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("min radius")
	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("min radius")
	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("min radius")
	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
