
! script name: v3dinter.d/fastintsurfs
! var_topic: fast intersection of two surfaces

!A
!A NAME:
!A
!A 	Fast Intersect Surfaces
!A
!A DESCRIPTION:
!A
!A 	This script will generate the path of intersection of two surfaces
!A 	using a fast algorithm.
!A
!B INSTRUCTIONS:
!B
!B 	PICK SURFACE #1: Pick one of the two surfaces to be used for the
!B 		intersection. Pick location determines curve generated.
!B
!B 	PICK SURFACE #2: Pick the other surface to be used for the 
!B		intersection.  Pick location determines curve generated.
!B
!C NOTES:
!C
!C 	The fast intersection may fail to give the desired fillet. This
!C 	method will generally fail if at least one of the surfaces varies
!C 	a great deal. If the intersection propagates through small radii 
!C 	the method will generally fail.
!C
!C	The fillet surface is generated in such a way as to propagate
!C	in the same direction as the u-curves in the first surface picked.
!C	This is done to insure consistant generation for vdm.
!C

stat=ChangeLabelStr("ScriptNameStatus","Function: fast intersect surfaces ")

DIM Destination$[256]
DIM Answer$[256]
DIM Surface_dir$[80]
DIM Name1$[256]
DIM Name2$[256]
DIM Name$[256]

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

Tol=NamedVarVal("3D Intersect Tol",Ws3DSystemVars,0.005)

ActivateUndo
Start:!
stat= Setup3dCutter(WsNullTool,0.0,0.0,0.0,0.0,0.0)
Intersect2:!

Pick_loop:!
Pick_surf1:Stat= SetPickMask(WsPickSurfOnly)
stat= SetInputFormat("n0","")
Surface1=PickEntity("PICK SURFACE #1",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(Surface1) THEN Pick_surf1
Stat= EntityNameCheck(Surface1,Name1$)

UVpoint1= LastUVSurfPick(Surface1)
IF NOT ValidGeometry(UVpoint1) THEN Pick_loop
U= XPointValue(UVpoint1)
V= YPointValue(UVpoint1)

Pick_surf2:Stat= SetPickMask(WsPickSurfOnly)
stat= SetInputFormat("n0","")
Surface2=PickEntity("PICK SURFACE #2",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(Surface2) THEN Pick_surf2
Stat= EntityNameCheck(Surface2,Name2$)

UVpoint2= LastUVSurfPick(Surface2)
IF NOT ValidGeometry(UVpoint2) THEN Pick_surf2
U= XPointValue(UVpoint2)
V= YPointValue(UVpoint2)

Stat= SetPickMask(WsPickGeometry)


Stat=SetPickMask(WsPickGeometry)
Uvalue1=XPointValue(UVpoint1)
Vvalue1=YPointValue(UVpoint1)
Uvalue2=XPointValue(UVpoint2)
Vvalue2=YPointValue(UVpoint2)
Stat=DeleteEntity(UVpoint1)
Stat=DeleteEntity(UVpoint2)

Normal_sign1= 1
Normal_sign2= 1
Stat= GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("CURVE: Intersect")
Stat= SetRecDelLastExec
stat= Set3dInterOffset(0.0)
V1= FreeParameter("Tolerance",Tol)
V2= FreeParameter("Sign1",Normal_sign1)
V3= FreeParameter("Sign2",Normal_sign2)
UVpoint1= PointXYZ(Uvalue1,Vvalue1,0)
UVpoint2= PointXYZ(Uvalue2,Vvalue2,0)
G1= FastIntSurfs(Name1$,V2,UVpoint1,Name2$,V3,UVpoint2,V1)
Stat= AutoNameGroup(G1,Name$)
Stat= SetNoPathFlag(G1,WsTrue)
Stat=DeleteEntityList(UVpoint1,UVpoint2)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(G1) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("intersect curve")
	Stat= AddGroupToUndo(WsUBCreateMode,G1,1,WsTrue)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
GOTO Intersect2

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