
! script name: vpksolids.d/vpkedgegroupblend
! var_solids: set blend radius on an edge

!A
!A NAME:
!A
!A 	Radius Blend Edge Group VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script sets a blend radius on an edge group.
!A
!B INSTRUCTIONS:
!B
!B
!B~ image location - images/pkradiusblend.gif
!B~ image location - images/pkblendtypes.gif
!B~ image location - images/pkcliffedge.gif
!B~ image location - images/pknotchblend.gif
!B
!C NOTE:
!C
!C	When the edge to be blended disappears to a tangent condition 
!C	the default blend will gradually disappear in a triangular shaped face.
!C	If the variable "solid y blend on" is set to 1 the blend will
!C	assume a "Y" like shape. (see diagram) If this variable is set
!C	the blends will be "y blends" where appropriate.
!C
!C	The variable "solid vertex blend on" will turn on vertex blending
!C	where it is suitable. Vertex blending allows users to blend
!C	smoothly past sharp edges of opposite convexity to the blend.
!C
!C	It may be possible that some blends which do not work properly
!C	when in propagate mode will work if each individual edge is
!C	selected and then are collectively fixed.
!C
!# see also - htdocs/help.d/parasolids.htm


stat=ChangeLabelStr("ScriptNameStatus","Function: set edge blend ")

OPTION BASE 1
DIM Destination$[256]
DIM Answer$[256]
DIM Edgegroup$[256]
DIM Radius_var$[256]
DIM Bodyname$[256]


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)


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

Stat= GLPlotOn
Start:!
Propagate= WsFalse
Stat=SetInputFormat("n4=","")
Stat=SetRadiusEquals(Radius)
Radius=InputRadius("RADIUS")
IF ExitScript(Destination$) THEN Leave
No_radius_var= LastVariableInput(Radius_var$)
C1= LastPickEnt
IF ValidGeometry(C1) THEN
        IF NOT ValidDependency(C1) THEN Cloop
        No_radius_var=0
        Stat= EntityNameCheck(C1,Radius_var$)
END IF
Vradius=CreateVariable("solid blend radius",WsPKSolidsVars,Radius)

E1=WPKPickEntity("PICK EDGE GROUP",WsPKPickEdge)
IF (ExitScript(Destination$)) THEN Leave
IF NOT WPKIsEntity(E1) THEN Start

Body= WPKParentBody(E1)
Pkgroup= WPKContainingGroup(E1,1)
IF NOT WPKIsEntity(Pkgroup) THEN Start

Stat= EntityNameCheck(Pkgroup,Edgegroup$)
Stat= EntityNameCheck(Body,Bodyname$)

WPKClearErrorFlag
RecordFunctionOn
Stat= RecordDescr("BLEND: Blend Edge Group")
V1= FreeParameter("Propagate on",Propagate)
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)
	Stat= WPKEdgeBlend(Edgegroup$,V9,V1,V5,V6,V7,V8)
ELSE
	Stat= WPKEdgeBlend(Edgegroup$,Radius_var$,V1,V5,V6,V7,V8)
END IF
Stat= WPKFixBlends(Bodyname$,V1,V4,V2,V3)
Stat= WPKNameBody(Bodyname$,Bodyname$)
Stat= WPKSetBodyParent(Bodyname$,1)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

ActivateUndo
Stat= WPKSolidRecordOn(Curr_record)
Stat= AdvanceUndoNumber("blend edge group")
Stat= AddItemToUndo(WsUBPKSessionMark)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
WPKErrorCheck

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=SetInputFormat("n4","")
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
