
! script name: parasolids.d/faceblend
! solids: create a blend between two or more faces.

!A
!A NAME:
!A
!A 	Face Blend
!A
!A DESCRIPTION:
!A
!A	This script creates a blend between two or more faces. 	
!A
!B INSTRUCTIONS:
!B
!B	RADIUS:   Input the radius of the blend.
!B	
!B	BLEND TRIM: None, Short, Long, To walls: Enter the blend trim method.
!B
!B		None:   The blend is not trimmed. 
!B		Short:  The blend is created as short as possible.
!B		Long:   The blend is created as long as possible.
!B		To walls: The blend is trimmed to be walls.(Default)
!B	
!B	WALL TRIM: None, Attach, Both, Walls solid: Enter the wall trim method.
!B
!B		None: The walls are not trimmed.
!B		Attach: The walls are trimmed and then the blend is attached
!B				to the walls.
!B		Both: The walls are trimmed. But not attached. Remain 
!B				separate sheet bodies.
!B		Walls solid. Same as attach, but if resulting sheet encloses
!B			a solid volume make into a solid.
!B
!B	PICK LEFT WALL FACES: Unpick, Clear, Proceed: Select the faces on the
!B		left wall of the blend.
!B
!B	PICK RIGHT WALL FACES: Unpick, Clear, Proceed: Select the faces on the
!B		right wall of the blend.
!B
!# see also - htdocs/help.d/parasolids.htm


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

OPTION BASE 1
DIM Destination$[256]
DIM Answer$[256]
REAL Left_array(100)
REAL Right_array(100)

ActivateUndo

Left_color=3
Right_color=4

Radius=NamedVarVal("solid blend radius",WsPKSolidsVars,0.0)
Stat= GLPlotOn
Start:!

Ask_radius:!
Stat=SetInputFormat("n4=","")
Stat=SetRadiusEquals(Radius)
Radius=InputRadius("RADIUS")
IF ExitScript(Destination$) THEN Leave

Blend_trim:!
Stat=SetInputFormat("a1=",",N,S,L,T,")
Stat= SetEqualsValue(0,"T")
Stat=GetValue("BLEND TRIM: None, Short, Long, To walls ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
SELECT Answer$
CASE "N"
	Blend_trim=0
CASE "T"
	Blend_trim=1
CASE "S"
	Blend_trim=2
CASE "L"
	Blend_trim=3
END SELECT

Wall_trim:!
Stat=SetInputFormat("a1=",",N,A,B,W,")
Stat= SetEqualsValue(0,"A")
Stat=GetValue("WALL TRIM: None, Attach, Both, Walls solid ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
SELECT Answer$
CASE "N"
	Blend_walls=0
CASE "A"
	Blend_walls=1
CASE "B"
	Blend_walls=2
CASE "W"
	Blend_walls=3
END SELECT

Start_left:!
Nleft= 0
Left_group=CreateGroup("TEMPGROUP")
Left_loop:!
Stat=SetInputFormat("a1",",P,U,C,")
E1=WPKPickEntity("PICK LEFT WALL FACES: Unpick ,Clear ,Proceed ",WsPKPickFace,Answer$)
IF (ExitScript(Destination$)) THEN Leave

SELECT Answer$
CASE "P"
	GOTO Start_right
CASE "U"
	Nleft= Nleft-1
	IF Nleft<0 THEN Nleft=0
	N1= GroupCount(Left_group)
	E1= GroupElement(Left_group,N1)
	Stat=RemoveFromGrp(Left_group,N1)
	Stat= DeleteEntity(E1)
	N1= GroupCount(Left_group)
	IF N1= 0 THEN 
		Stat= DeleteEntity(Ps)
	END IF
	PlotAll
	GOTO Left_loop
CASE "C"
	Stat= DeleteGroup(Left_group,WsTrue)
	Stat= DeleteEntity(Ps)
	PlotAll
	GOTO Start_left
END SELECT

IF Nleft= 99 THEN Start_left
IF NOT WPKIsEntity(E1) THEN Left_loop

UVpoint=LastUVSurfPick(E1)
IF NOT ValidGeometry(UVpoint) THEN Left_loop
U=XPointValue(UVpoint)
V=YPointValue(UVpoint)
Stat= DeleteEntity(UVPoint)

Face1= WPKEntityTag(E1)
FOR I= 1 TO Nleft
	IF Face1= Left_array(I) THEN Left_loop
NEXT I
Nleft= Nleft+1
Left_array(Nleft)= Face1
Pt= SurfParameterPt(E1,U,V)
Stat= SetColor(Pt,Left_color,WsTrue)
Stat= AddToGroup(Left_group,Pt)
GOTO Left_loop


Start_right:!
Nright= 0
Right_group=CreateGroup("TEMPGROUP")
Right_loop:!
Stat=SetInputFormat("a1",",P,U,C,")
E1=WPKPickEntity("PICK RIGHT WALL FACES: Unpick ,Clear ,Proceed ",WsPKPickFace,Answer$)
IF (ExitScript(Destination$)) THEN Leave

SELECT Answer$
CASE "P"
	GOSUB Make_blend
	GOTO Start
CASE "U"
	Nright= Nright-1
	IF Nright<0 THEN Nright=0
	N1= GroupCount(Right_group)
	E1= GroupElement(Right_group,N1)
	Stat=RemoveFromGrp(Right_group,N1)
	Stat= DeleteEntity(E1)
	N1= GroupCount(Right_group)
	IF N1= 0 THEN 
		Stat= DeleteEntity(Ps)
	END IF
	PlotAll
	GOTO Right_loop
CASE "C"
	Stat= DeleteGroup(Right_group,WsTrue)
	Stat= DeleteEntity(Ps)
	PlotAll
	GOTO Start_right
END SELECT

IF Nright= 99 THEN Start_right
IF NOT ValidGeometry(E1) THEN Right_loop

UVpoint=LastUVSurfPick(E1)
IF NOT ValidGeometry(UVpoint) THEN Right_loop
U=XPointValue(UVpoint)
V=YPointValue(UVpoint)
Stat= DeleteEntity(UVPoint)

Face1= WPKEntityTag(E1)
FOR I= 1 TO Nright
	IF Face1= Right_array(I) THEN Right_loop
NEXT I
Nright= Nright+1
Right_array(Nright)= Face1
Pt= SurfParameterPt(E1,U,V)
Stat= SetColor(Pt,Right_color,WsTrue)
Stat= AddToGroup(Right_group,Pt)
GOTO Right_loop







Make_blend:!
WPKClearErrorFlag

Pt= GroupElement(Left_group,1)

Left_sense= WsFalse
Right_sense= WsFalse
Propagate= WsTrue

WPKClearErrorFlag
Stat= WPKFacesBlend(Radius,Nleft,Left_array,Nright,Right_array,Left_sense,Right_sense,Pt,Propagate,Blend_trim,Blend_walls)

Stat= DeleteGroup(Left_group,WsTrue)
Stat= DeleteGroup(Right_group,WsTrue)

ActivateUndo
Stat= AdvanceUndoNumber("face blend")
Stat= AddItemToUndo(WsUBPKSessionMark)
WPKErrorCheck
RETURN


Leave:!
Stat= DeleteGroup(Left_group,WsTrue)
Stat= DeleteGroup(Right_group,WsTrue)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
