
! script name: vcontours.d/sharpcorners
! var_topic: make small corner radii sharp.

!A
!A NAME:
!A
!A 	Makes Sharp Contour Corners   VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script make small corner radii on a contour sharp. The original
!A	contour will be hidden by the variational record.
!A
!B INSTRUCTIONS:
!B
!B 	PICK CONTOUR: Pick an element on the contour.
!B
!B 	MINIMUM RADIUS FOR SHARP CORNER: Input
!B 		the minimum radius to be used on corners. All
!B 		radii smaller than this amount will be made into
!B 		sharp corners.
!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	If this function is used on a machining path it will be
!C	necessary to associate the tool with the new contour. It may
!C	also be necessary to variationally delete the original contour.
!C	Be warned that this routine should not be used variationally on
!C	non-variational geometry.
!C
!C 	CAUTION Do not use these contours for surfacing.
!C
!C	The original contour is deleted.
!C

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

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Contour$[256]
DIM Radius_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/sharpcorners"
   Stat=SetInputFormat("n4","")
   GOTO Leave
END IF

Min_radius:!
Radius=InputRadius("MINIMUM RADIUS FOR SHARP CORNERS")
IF ExitScript(Destination$) THEN Leave
No_radius_var=LastVariableInput(Radius_var$)
C1=LastPickEnt
IF ValidGeometry(C1) THEN
	IF NOT ValidDependency(C1) THEN Min_radius
	No_radius_var=0
	Stat=EntityNameCheck(C1,Radius_var$)
END IF

Stat=GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat=RecordDescr("CONTOUR: Sharp corner radii")
IF No_radius_var THEN
	V1=FreeParameter("Min Corner Radius",Radius)
ELSE
	V1=FreeParameter("Min Corner Radius",Radius_var$)
END IF
C1=MinRadiusCorners(Contour$,V1,V1,WsTrue)
RecordFunctionOff
IF ValidGeometry(C1) THEN
	RecordFunctionOn
	Stat=AutoNameGroup(C1,Name$)

	ActivateUndo
	Stat= AdvanceUndoNumber("sharp corners")
	Stat= AddGroupToUndo(WsUBDeleteMode,Contour$,1,WsTrue)

	Stat=DeleteGroup(Contour$,WsTrue)
	RecordFunctionOff
	Stat=PlotEntity(C1)
END IF
RecordFunctionOn
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(C1) THEN
	DelLastVarRecord
END IF

Stat= AddGroupToUndo(WsUBCreateMode,C1,1,WsTrue)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
GOTO Pick_contour

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

