
! script name: 3dextend.d/nedgetangent
! var_topic: extend edge curve with tangent nurb surface

!A
!A NAME:
!A
!A 	Tangent Extend Edge: nurb	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will create a new nurb surface by extending the edge of
!A 	the surface the specified distance.  The new surface, which extends the
!A 	edge of the original surface, will be tangent to the original surface.
!A
!B INSTRUCTIONS:
!B
!B 	EXTENSION DISTANCE: Enter the amount of extension.
!B
!B 	PATCH WIDTH ALONG EDGES: Enter the width of the patch to be used along
!B 		the edge.
!B
!B 	PICK EDGE CURVE ON SURFACE : Pick the edge curve on surface.
!B

Stat=ChangeLabelStr("ScriptNameStatus","Function: nurb edge tangent extension")

DIM Destination$[256]
DIM Answer$[256]
DIM Surface_dir$[80]
DIM Surface$[256]
DIM Ext_var$[256]
DIM Name$[256]
DIM Patch_var$[256]

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

IF ARGC<2 THEN
        Ext_type= WsTangent
ELSE
        Ext_type= WsPlaneTangentExt
END IF

ActivateUndo
Patch_width=NamedVarVal("3D Default Patch",Ws3DSystemVars,0.25)
Tol=NamedVarVal("3D Fillet Tol",Ws3DSystemVars,0.005)

Start:!

stat= SetInputFormat("n4=","")
stat= SetEqualsValue(Extend_dist)
Extend_dist= GetValue("EXTENSION DISTANCE",Answer$)
IF (ExitScript(Destination$)) THEN Leave
No_dist_var= LastVariableInput(Ext_var$)
IF Extend_dist=0 THEN Start

stat= SetInputFormat("n4=","")
stat= SetEqualsValue(Patch_width)
V_width= GetValue("PATCH WIDTH ALONG EDGES",Answer$)
IF (ExitScript(Destination$)) THEN Leave
No_patch_var= LastVariableInput(Patch_var$)
U_width= V_width
Patch_width= V_width

Intersect2:!
Pick_loop:!
Stat= SetPickMask(WsPickSurfOnly)
stat= SetInputFormat("n4","")
Surface=PickEntity("PICK EDGE CURVE ON SURFACE ")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(Surface) THEN Pick_loop
Stat= EntityNameCheck(Surface,Surface$)

GOSUB Which_edge
IF NOT Surf_edge THEN Intersect2
Which1= Surf_edge
Dir1= Edge_dir

Stat= SetPickMask(WsPickGeometry)
Para_value1= 0.0
Dist= Esign*Extend_dist


Stat= GenerateVarName(WsNurbSurfEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("NURB: Tangent edge extension")
Stat= SetRecDelLastExec
Stat= Set3dInterOffset(0.0)
V1= FreeParameter("Which edge",Which1)
V2= FreeParameter("Direction",Dir1)
V3= FreeParameter("Tolerance",Tol)
IF No_dist_var THEN
        V4= FreeParameter("Distance",Extend_dist)
ELSE
        V4= FreeParameter("Distance",Ext_var$)
END IF
IF No_patch_var THEN
        V5= FreeParameter("Patch width",Patch_width)
ELSE
        V5= FreeParameter("Patch width",Patch_var$)
END IF
RecordFunctionOff
IF Ext_type= WsPlaneTangentExt THEN
RecordFunctionOn
S1=EdgeExtendSurf(WsPlaneTangentExt,WsNurbSurfEnt,Surface$,V1,V2,Esign*GetVariableVal(v4),V5,V5,V3,Para_value)
RecordFunctionOff
ELSE
RecordFunctionOn
S1=EdgeExtendSurf(WsTangent,WsNurbSurfEnt,Surface$,V1,V2,Esign*GetVariableVal(v4),V5,V5,V3,Para_value)
RecordFunctionOff
END IF
RecordFunctionOn
Stat= NameEntity(S1,Name$)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(S1) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("nurb ext surf")
	Stat= AddItemToUndo(WsUBCreateMode,S1)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
GOTO Intersect2


Which_edge: Surf_edge= 0
Edge_dir= WsForward
Pt= LastUVSurfPick(Surface)
IF NOT ValidGeometry(Pt) THEN RETURN
U= XPointValue(Pt)
V= YPointValue(Pt)
stat= DeleteEntity(Pt)
Surf_edge= ClosestSurfEdge(Surface,U,V)

Esign= 1
SELECT Surf_edge
CASE 1,3
        Edge_dir= WsForward
        IF(U> 0.5) THEN Edge_dir= WsReverse
	IF(V< 0.5) THEN Esign= -1
CASE 2,4
        Edge_dir= WsForward
        IF(V> 0.5) THEN Edge_dir= WsReverse
	IF(U< 0.5) THEN Esign= -1
END SELECT
RETURN 



Leave:!
Stat= SetPickMask(WsPickGeometry)
stat= SetInputFormat("n4","")
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
