
! script name: parasolids.d/blendallsharp
! solids: blend all sharp edges

!A
!A NAME:
!A
!A 	Radius Blend All Sharp Edges
!A
!A DESCRIPTION:
!A
!A 	This script blends all sharp edges with a constant radius.
!A
!B INSTRUCTIONS:
!B
!B	PICK BODY: Pick the body.
!B
!B
!C NOTE:
!C
!C	This script will attempt to blend all sharp edges in a
!C	body. 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
!C
!# see also - htdocs/help.d/parasolids.htm


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

OPTION BASE 1
DIM Destination$[256]
DIM Answer$[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
Start:!
GOSUB Ask_radius

Pick_loop:!
E1=WPKPickEntity("PICK BODY")
IF (ExitScript(Destination$)) THEN Leave
IF NOT WPKIsEntity(E1) THEN Pick_loop

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

GOSUB Fix_blends
Stat= WPKRemoveGroup(Pkgroup)
GOTO Leave

Fix_blends:!
	Propagate= WsTrue
	WPKClearErrorFlag
	Num_edges= WPKGroupCount(Pkgroup)
	Stat= WPKEdgeBlend(Pkgroup,Radius,WsFalse,Smooth_overflow,Cliff_overflow,Cliff_end_overflow,Notch_overflow)
	Stat= WPKUnSetBadBlends(Pkbody)
	Stat= WPKFixBlends(Pkbody,Propagate,Angle_tol,Yblendon,Vertexblendon)
	ActivateUndo
	Stat= AdvanceUndoNumber("edge blend")
	Stat= AddItemToUndo(WsUBPKSessionMark)
	WPKErrorCheck
RETURN

Ask_radius:!
Stat=SetInputFormat("n4=","")
Stat=SetRadiusEquals(Radius)
Radius=InputRadius("RADIUS")
IF ExitScript(Destination$) THEN Leave
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
