
! script name: vcontours.d/mincornerrad
! var_topic: minimum radii on contour corners

!A
!A NAME:
!A
!A 	Minimum Radii		VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script automatically checks for minimum radii on contour corners.
!A
!B INSTRUCTIONS:
!B
!B 	PICK CONTOUR TO BE CHANGED: Pick an element
!B 		on the contour to be changed.
!B
!B 	MINIMUM RADIUS FOR CW CORNERS: Enter
!B 		the minimum radius to be used on corners
!B 		traversed in a clockwise fashion.
!B
!B 	MINIMUM RADIUS FOR CCW CORNERS: Enter
!B 		the minimum radius to be used on corners
!B 		traversed in a counterclockwise fashion.
!B
!C NOTES:
!C
!C 	This function will check each radius of a contour and see if it
!C 	satisfies the minimum radii conditions.  If a radius does not satisfy
!C 	the minimum conditions, the corner will be regenerated with the
!C 	appropriate minimum radius. It is assumed that this minimum radius will
!C 	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 will fit into the
!C 	elements without eliminating elements.  If the fillet does not fit, then
!C 	either no corner will be generated or the corner radius will be
!C 	generated incorrectly.  It is the operator's responsibility to verify
!C 	that the newly created contour is a valid contour.
!C
!C	The original contour is deleted.
!C

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

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

Var_object=CheckVarObject
IF ExitScript(Destination$) THEN Leave

ActivateUndo
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/mincornerrad"
   Stat=SetInputFormat("n4","")
   GOTO Leave
END IF

Min_cw_rad:!
R1=InputRadius("MINIMUM RADIUS FOR CW CORNERS")
IF ExitScript(Destination$) THEN Leave
No_radius1_var=LastVariableInput(Radius1_var$)
C1=LastPickEnt
IF ValidGeometry(C1) THEN
	IF NOT ValidDependency(C1) THEN Min_cw_rad
	No_radius1_var=0
	Stat=EntityNameCheck(C1,Radius1_var$)
END IF

Min_ccw_rad:!
R2=InputRadius("MINIMUM RADIUS FOR CCW CORNERS")
IF ExitScript(Destination$) THEN Leave
No_radius2_var=LastVariableInput(Radius2_var$)
C2=LastPickEnt
IF ValidGeometry(C2) THEN
	IF NOT ValidDependency(C2) THEN Min_ccw_rad
	No_radius2_var=0
	Stat=EntityNameCheck(C2,Radius1_var$)
END IF

Stat=GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat=RecordDescr("CONTOUR: Minimum corner radii")
IF No_radius1_var THEN
	V1=FreeParameter("CW Corner Radius",R1)
	IF No_radius2_var THEN
		V2=FreeParameter("CCW Corner Radius",R2)
		C1=MinRadiusCorners(Contour$,V1,V2)
	ELSE
		C1=MinRadiusCorners(Contour$,V1,Radius2_var$)
	END IF
ELSE
	IF No_radius2_var THEN
		V2=FreeParameter("CCW Corner Radius",R2)
		C1=MinRadiusCorners(Contour$,Radius1_var$,V2)
	ELSE
		C1=MinRadiusCorners(Contour$,Radius1_var$,Radius2_var$)
	END IF
END IF
RecordFunctionOff
IF ValidGeometry(C1) THEN
	RecordFunctionOn
	Stat=AutoNameGroup(C1,Name$)
	Tool= GetAssocTool(Contour$)

	ActivateUndo
	Stat= AdvanceUndoNumber("min radii")
	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:!
Stat=SetInputFormat("n4","")
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END

