
! script name: parasolids.d/variableblend
! solids: linear variable radius blend

!A
!A NAME:
!A
!A 	Variable Blend
!A
!A DESCRIPTION:
!A
!A 	This script sets a variable blend radius on an edge.
!A
!A~ image location - images/pkvariableblend.gif
!A
!B INSTRUCTIONS:
!B
!B	PICK EDGE: Fix, Propagate, Unpick ,Restore: Select the edges which will
!B 		receive the radius blend.  Different edges may have different
!B 		radii.  When all the desired edges have been selected the blend
!B 		must be either fixed or propagated to become effective.  Fixing
!B 		puts blends only on the edges selected.  Propagate will cause
!B 		tangent connecting edges to also be blended. You cannot
!B 		propagate from one radius to a different radius.
!B		
!C NOTE:
!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: variable edge blend ")

OPTION BASE 1
DIM Destination$[256]
DIM Answer$[256]
REAL Edge_array(100,4)

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)
Make_sheets=NamedVarVal("solid blend make sheets",WsPKSolidsVars,0.0)

Radius1= Radius
Radius2= Radius


Stat= GLPlotOn
Start:!
Propagate= WsFalse
Num_edges= 0
Group=CreateGroup("TEMPGROUP")


Edge_loop:!
Stat=SetInputFormat("a1",",F,U,R,P,")
E1=WPKPickEntity("PICK EDGE: Fix, Propagate, Unpick ,Restore ",WsPKPickEdge,Answer$)
IF (ExitScript(Destination$)) THEN Leave

T= LastPickPara
IF T < 0.5 THEN
	T1= 0.0
	T2= 1.0
	Edge_dir= WsForward
ELSE
	T1= 1.0
	T2= 0.0
	Edge_dir= WsReverse
END IF


SELECT Answer$
CASE "P"
	Propagate= WsTrue
	GOSUB Fix_blends
	GOTO Start
CASE "F"
	GOSUB Fix_blends
	GOTO Start
CASE "U"
	Num_edges= Num_edges-1
	IF Num_edges<0 THEN Num_edges=0
	N1= GroupCount(Group)
	E1= GroupElement(Group,N1)
	Stat=RemoveFromGrp(Group,N1)
	Stat= DeleteEntity(E1)
	PlotAll
	GOTO Edge_loop
CASE "R"
	Stat= DeleteGroup(Group,WsTrue)
	PlotAll
	GOTO Start
END SELECT
IF Num_edges= 99 THEN Start

IF NOT WPKIsEntity(E1) THEN Edge_loop
Num_edges= Num_edges+1
Edge1= WPKEntityTag(E1)
Edge_array(Num_edges,1)= Edge1
GOSUB Ask_radii

Edge_array(Num_edges,2)= Radius1
Edge_array(Num_edges,3)= Radius2
Edge_array(Num_edges,4)= Edge_dir
Pt= ParameterPt(E1,0.5)
Stat= SetColor(Pt,Pick_color,WsTrue)
Stat= AddToGroup(Group,Pt)
GOTO Edge_loop

Fix_blends:!
	Stat= DeleteGroup(Group,WsTrue)
	FOR I= 1 TO Num_edges
	   Edge1= Edge_array(I,1)
	   Radius1= Edge_array(I,2)
	   Radius2= Edge_array(I,3)
	   Edge_dir= Edge_array(I,4)
	   Stat= WPKVariableBlend(Edge1,Radius1,Radius2,Edge_dir,Propagate,WsFalse,Smooth_overflow,Cliff_overflow,Cliff_end_overflow,Notch_overflow)
	NEXT I
	WPKClearErrorFlag
	Stat= WPKFixBlends(Edge1,Propagate,Angle_tol,Yblendon,Vertexblendon,Make_sheets)
	ActivateUndo
	Stat= AdvanceUndoNumber("edge blend")
	Stat= AddItemToUndo(WsUBPKSessionMark)
	WPKErrorCheck
RETURN

Ask_radii:!
P1= ParameterPt(E1,T1)
Stat= SetColor(P1,Start_color,WsTrue)
Stat=SetInputFormat("n4=","")
Stat=SetRadiusEquals(Radius1)
Radius1=InputRadius("START RADIUS")
IF ExitScript(Destination$) THEN Leave
Vradius=CreateVariable("solid blend radius",WsPKSolidsVars,Radius1)

P2= ParameterPt(E1,T2)
Stat= SetColor(P2,End_color,WsTrue)
Stat=SetInputFormat("n4=","")
Stat=SetRadiusEquals(Radius2)
Radius2=InputRadius("END RADIUS")
IF ExitScript(Destination$) THEN Leave
Vradius=CreateVariable("solid blend radius",WsPKSolidsVars,Radius2)


Stat= DeleteEntity(P1,WsTrue)
Stat= DeleteEntity(P2,WsTrue)
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)
V8=CreateVariable("solid blend make sheets",WsPKSolidsVars,Make_sheets)
Stat= DeleteGroup(Group,WsTrue)
Stat= DeleteEntity(P1)
Stat= DeleteEntity(P2)
Stat=SetPickReturn(WsGeometryEnd)
Stat=SetInputFormat("n4","")
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
