
! script name: vpksolids.d/vpkconicblend
! var_solids: set conic profile blend on an edge

!A
!A NAME:
!A
!A 	Conic Profile Blend  VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script sets a conic profile blend  on an edge.
!A
!B INSTRUCTIONS:
!B
!B	LEFT OFFSET: Give the offset distance applied to the face to the
!B			left side of the edge.
!B
!B	RIGHT OFFSET: Give the offset distance applied to the face to the
!B			right side of the edge.
!B
!B	Right and left are relative to the edge direction. 
!B
!B	RHO FACTOR 0.0(ellipse) 0.5(parabola) 1.0(hyperbola) The rho factor
!B		determines the conic shape. A rho of 0.0 will give an
!B		elliptical shape. A rho of 0.5 will be parabolic. A rho
!B		greater than 0.5 will give a hyperbola which will become
!B		"L" shaped as rho approaches 1.0.
!B
!B	For simplicity sake, the above data does not take variable input
!B	If necessary variables may be added to the free parameters in the
!B	record after creation.
!B
!B 	PICK EDGE: Fix, Propagate, New distances, Unpick ,Restore: Select the
!B 		edges which will receive the conic blend.  Different edges
!B 		may have different data.  When all the desired edges have been
!B 		selected the blend must be either fixed or propagated to become
!B 		effective.  Fixing just puts blends on the edges selected.
!B		Propagate will cause tangent connecting edges to also be
!B 		blended. 
!B
!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 conic profile blend")

OPTION BASE 1
DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Edgename$[256]
DIM Bodyname$[256]
DIM Name$[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)

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

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

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

SELECT Answer$
CASE "P"
	Propagate= WsTrue
	GOSUB Fix_blends
	GOTO Start
CASE "F"
	GOSUB Fix_blends
	GOTO Start
CASE "N"
	GOSUB Ask_distances
	GOTO Edge_loop
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
Edge_array(Num_edges,1)= WPKEntityTag(E1)
Edge_array(Num_edges,2)= Left_offset
Edge_array(Num_edges,3)= Right_offset
Edge_array(Num_edges,4)= Rho_factor
Pt= ParameterPt(E1,0.5)
Stat= SetColor(Pt,Pick_color,WsTrue)
Stat= AddToGroup(Group,Pt)
GOTO Edge_loop

Fix_blends:!
	Stat= DeleteGroup(Group,WsTrue)

	WPKClearErrorFlag
	RecordFunctionOn
	Stat= RecordDescr("BLEND: conic profile blend")
	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)
	RecordFunctionOff
	Left_offsetr= 0.0
	Right_offsetr= 0.0
	Rho_factorr= -1.0
	Rcount=1
	FOR I= 1 TO Num_edges
		RecordFunctionOff
		Edge1= Edge_array(I,1)
		Left_offset= Edge_array(I,2)
		Right_offset= Edge_array(I,3)
		Rho_factor= Edge_array(I,4)
		Edgename$= WPKEntityName(Edge1)
		Bodyname$= WPKBodyName(Edge1)
		Do_parameters=0
		IF I=1 THEN Do_parameters=1
		IF ABS(Left_offset-Left_offsetr)> 0.00001 THEN Do_parameters=1
                IF ABS(Right_offset-Right_offsetr)> 0.00001 THEN Do_parameters=1
		IF ABS(Rho_factor-Rho_factorr)> 0.00001 THEN Do_parameters=1
		IF Do_parameters THEN
                	A$= "Left offset"&VAL$(Rcount)
			RecordFunctionOn
			V9= FreeParameter(A$,Left_offset)
			RecordFunctionOff
			Left_offsetr= Left_offset
		
			A$= "Right offset"&VAL$(Rcount)
                        RecordFunctionOn
                        V10= FreeParameter(A$,Right_offset)
                        RecordFunctionOff
                        Right_offsetr= Right_offset
		
			A$= "Rho factor"&VAL$(Rcount)
                        RecordFunctionOn
                        V11= FreeParameter(A$,Rho_factor)
                        RecordFunctionOff
                        Rho_factorr= Rho_factor

                	Rcount= Rcount+1
                END IF
		RecordFunctionOn
		Stat= WPKConicBlend(Edgename$,V9,V10,V11,V1,V5,V6,V7,V8)
		RecordFunctionOff
	NEXT I
	RecordFunctionOn
	Stat= WPKFixBlends(Bodyname$,V1,V4,V2,V3)
	Stat= WPKNameBody(Bodyname$,Bodyname$)
	Stat= WPKSetBodyParent(Bodyname$,1)
	RecordFunctionOff
	Curr_record= CurrentVarRecord
	CloseVarRecord

	Stat= WPKSolidRecordOn(Curr_record)
	ActivateUndo
	Stat= AdvanceUndoNumber("conic profile blend")
	Stat= AddItemToUndo(WsUBPKSessionMark)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
	WPKErrorCheck

RETURN

Ask_distances:!
Stat=SetInputFormat("n4=","")
Stat=SetRadiusEquals(Left_offset)
Left_offset=InputRadius("LEFT OFFSET")
IF ExitScript(Destination$) THEN Leave

Stat=SetRadiusEquals(Right_offset)
Right_offset=InputRadius("RIGHT OFFSET")
IF ExitScript(Destination$) THEN Leave

Stat=SetRadiusEquals(Rho_factor)
Rho_factor=InputRadius("RHO FACTOR 0.0(ellipse) 0.5(parabola) 1.0(hyperbola)")
IF ExitScript(Destination$) THEN Leave
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
