
! script name: vpksolids.d/vpkblendsharpfaceedges
! var_solids: blend sharp edges on a face

!A
!A NAME:
!A
!A 	Blend Face Sharp Edges	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script blends sharp edges on a face with a constant radius.
!A
!B INSTRUCTIONS:
!B
!B 	PICK FACE: Pick the face.
!B
!C NOTE:
!C
!C	This script will attempt to blend all sharp edges on a
!C	face. Before blending it will do a check on the edge.
!C	If the check indicates that the blend will fail it will
!C	be removed from the list of edges to be blended.
!C
!# see also - htdocs/help.d/parasolids.htm


stat=ChangeLabelStr("ScriptNameStatus","Function: blend sharp face edges ")

OPTION BASE 1
DIM Destination$[256]
DIM Answer$[256]
DIM Body$[256]
DIM Face$[256]
DIM Radius_var$[256]


Start_color= 3
End_color= 4
Pick_color= 2

Radius=NamedVarVal("solid blend radius",WsPKSolidsVars,0.0)
Yblendon=NamedVarVal("solid y blend on",WsPKSolidsVars,0.0)
Vertexblendon=NamedVarVal("solid vertex blend on",WsPKSolidsVars,0.0)
Angle_tol=NamedVarVal("solid blend propagate angle",WsPKSolidsVars,1.0)
Smooth_overflow=NamedVarVal("solid blend smooth overflow",WsPKSolidsVars,1.0)
Cliff_overflow=NamedVarVal("solid blend cliff overflow",WsPKSolidsVars,1.0)
Cliff_end_overflow=NamedVarVal("solid blend cliff end overflow",WsPKSolidsVars,0.0)
Notch_overflow=NamedVarVal("solid blend notch overflow",WsPKSolidsVars,1.0)


Stat= GLPlotOn
Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave
Start:!
GOSUB Ask_radius

Ploop:!
Stat=SetInputFormat("n4","")
E1=WPKPickEntity("PICK FACE",WsPKPickFace)
IF (ExitScript(Destination$)) THEN Leave
IF NOT WPKIsEntity(E1) THEN Face_loop
Stat= EntityNameCheck(E1,Face$)

Pkbody= WPKParentBody(E1)
Stat= EntityNameCheck(Pkbody,Body$)

Pkgroup= WPKSharpEdgeGroup(E1,2)
IF NOT WPKIsEntity(Pkgroup) THEN Pick_loop

GOSUB Fix_blends
Stat= WPKRemoveGroup(Pkgroup)
GOTO Leave

Fix_blends:!
	WPKClearErrorFlag
	RecordFunctionOn
	Stat= RecordDescr("BLEND: blend sharp face edges")
	V1= FreeParameter("Propagate on",1)
        V2= FreeParameter("Y blend on",Yblendon)
        V3= FreeParameter("Vertex blend on",Vertexblendon)
        V4= FreeParameter("Propagate angle",Angle_tol)
	V5= FreeParameter("Smooth overflow",Smooth_overflow)
        V6= FreeParameter("Cliff overflow",Cliff_overflow)
        V7= FreeParameter("Cliff end overflow",Cliff_end_overflow)
        V8= FreeParameter("Notch overflow",Notch_overflow)
	IF No_radius_var THEN
       		 V9= FreeParameter("Radius",Radius)
	ELSE
       		 V9= FreeParameter("Radius",Radius_var$)
	END IF
	Pkgroup= WPKSharpEdgeGroup(Face$,2)
	Stat= WPKEdgeBlend(Pkgroup,V9,V1,V5,V6,V7,V8)
	Stat= WPKUnSetBadBlends(Body$)
	Stat= WPKFixBlends(Body$,V1,V4,V2,V3)
	Stat= WPKRemoveGroup(Pkgroup)
	Stat= WPKNameBody(Body$,Body$)
        Stat= WPKSetBodyParent(Body$,1)
        RecordFunctionOff
        Curr_record= CurrentVarRecord
        CloseVarRecord

	Stat= WPKSolidRecordOn(Curr_record)
        ActivateUndo
        Stat= AdvanceUndoNumber("blend sharp face edges")
        Stat= AddItemToUndo(WsUBPKSessionMark)
        Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
        WPKErrorCheck

RETURN

Ask_radius:!
Stat=SetInputFormat("n4=","")
Stat=SetRadiusEquals(Radius)
Radius=InputRadius("RADIUS")
IF ExitScript(Destination$) THEN Leave
No_radius_var= LastVariableInput(Radius_var$)
Vradius=CreateVariable("solid blend radius",WsPKSolidsVars,Radius)
RETURN


Leave:!
V1=CreateVariable("solid y blend on",WsPKSolidsVars,Yblendon)
V2=CreateVariable("solid vertex blend on",WsPKSolidsVars,Vertexblendon)
V3=CreateVariable("solid blend propagate angle",WsPKSolidsVars,Angle_tol)
V4=CreateVariable("solid blend smooth overflow",WsPKSolidsVars,Smooth_overflow)
V5=CreateVariable("solid blend cliff overflow",WsPKSolidsVars,Cliff_overflow)
V6=CreateVariable("solid blend cliff end overflow",WsPKSolidsVars,Cliff_end_overflow)
V7=CreateVariable("solid blend notch overflow",WsPKSolidsVars,Notch_overflow)
Stat= DeleteGroup(Group,WsTrue)
Stat=SetPickReturn(WsGeometryEnd)
Stat=SetInputFormat("n4","")
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
