
! script name: vtrimming.d/cornerptfillet
! var_topic: corner point fillet

!A
!A NAME:
!A
!A 	Corner Point Fillet          VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script constructs a fillet at a corner between two elements.
!A	The elements must be trimmed to their intersection point.
!A	This fillet may be used in VDM to create fillets which are stable
!A	even when the direction of a corner changes.
!A
!A
!B INSTRUCTIONS:
!B
!B 	FILLET RADIUS: Enter the radius of the arc that should be constructed
!B 		tangent to each element picked.
!B
!B 	PICK FIRST TANGENT ELEMENT, New Radius: Pick one of the elements that
!B 		should be tangent to the arc constructed.
!B
!B 		N - Enter N to enter a new fillet radius.
!B
!B 	PICK NEXT TANGENT ELEMENT: Pick the other element that should be
!B 		tangent to the arc constructed.
!B

Stat=ChangeLabelStr("ScriptNameStatus","Function: corner point fillet ")

DIM Destination$[256]
DIM Answer$[256]
DIM Name1$[256]
DIM Name2$[256]
DIM Name$[256]
DIM Radius_var$[256]

DEG
Var_object=CheckVarObject
IF ExitScript(Destination$) THEN Leave

ActivateUndo
Ask_radius: !
Stat=SetInputFormat("n4=","")
Radius=InputRadius("FILLET RADIUS")
IF ExitScript(Destination$) THEN Leave
No_radius_var=LastVariableInput(Radius_var$)
C1=LastPickEnt
IF ValidGeometry(C1) THEN
	IF NOT ValidDependency(C1) THEN Ask_radius
	No_radius_var=0
	Stat=EntityNameCheck(C1,Radius_var$)
END IF

Ploop: !
Stat=SetInputFormat("a1",",N,")
E1=PickEntity("PICK FIRST TANGENT ELEMENT,  New radius",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$="N" THEN Ask_radius
IF NOT ValidDependency(E1) THEN Ploop
Stat=EntityNameCheck(E1,Name1$)

Pick_tan2: !
Stat=SetInputFormat("n4","")
E2=PickEntity("PICK NEXT TANGENT ELEMENT")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(E2) THEN Pick_tan2
Stat=EntityNameCheck(E2,Name2$)

ActivateUndo
Stat= AdvanceUndoNumber("fillet")
Stat= AddItemToUndo(WsUBModifyMode,Name1$)
Stat= AddItemToUndo(WsUBModifyMode,Name2$)

Stat=GenerateVarName(WsCircleEnt,Name$)
RecordFunctionOn
Stat=RecordDescr("CIRCLE: Corner point fillet")
IF No_radius_var THEN
	V1=FreeParameter("Radius",Radius)
	C1=CornerPointFillet(V1,Name1$,Name2$)
ELSE
	C1=CornerPointFillet(Radius_var$,Name1$,Name2$)
END IF
Stat=NameEntity(C1,Name$)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= PlotEntity(C1)
Stat= PlotEntity(Name1$)
Stat= PlotEntity(Name2$)
IF NOT ValidGeometry(C1) THEN
	DelLastVarRecord
ELSE
	Stat= AddItemToUndo(WsUBCreateMode,C1)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
GOTO Ploop

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

