
! script name: v3dcpaths.d/edgeextsw
! var_topic: auto edge extension in 3d gouge

!A
!A NAME:
!A
!A 	Auto edge extension: Surface Edge On  VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script turns on the auto extension of edges on a surface, and
!A 	is used in association with the gouge check routines.  Selected edges
!A 	will extend tangentially from the surface and roll the normal vector
!A 	through 90 deg of arc.
!A
!B INSTRUCTIONS:
!B
!B 	PICK EDGE CURVE ON SURFACE: Pick the edge curve on surface.
!B

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

DIM Destination$[256]
DIM Answer$[256]
DIM Surface$[256]

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

DeActivateUndo
Start:!
StdWorkplane
Pick_edge:!
Stat=SetPickMask(WsPickSurfOnly)
Stat=SetInputFormat("n0","")
Surface=PickEntity("PICK EDGE CURVE ON SURFACE ",Answer$)
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(Surface) THEN Pick_edge
Stat= EntityNameCheck(Surface,Surface$)

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

Stat=SetPickMask(WsPickGeometry)

RecordFunctionOn
Stat= RecordDescr("PROPERTY: Set Surface Auto Edge Ext")
Stat= NullReference(Surface$)
V1= FreeParameter("Which edge",which1)
Stat=SetEdgeExt(Surface$,V1)
RecordFunctionOff
CloseVarRecord

GOTO Pick_edge

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
