
! script name: surfaces.d/nurbarcblend
! 3dtopic: construct nurb surface using equal arc length

!A
!A NAME:
!A
!A 	NURBS: Arc Length
!A
!A DESCRIPTION:
!A
!A 	This script will make a nurb surface.  The points generated are used
!A 	as control points and the surface might not actually pass through
!A 	the control points.  The sections do not have to have the same number
!A 	of elements.  The longest section and the distance between control
!A 	points will determine the number of segments used to create the NURBS
!A 	surface.  Each section will be divided into the same number of patches,
!A 	but the patch width will vary depending on the length of the other
!A 	sections.  The order and position of the pick on the contours will
!A 	determine the direction.  The equal arc length NURBS blend will not
!A 	necessarily give the best surface.
!A
!B INSTRUCTIONS:
!B
!B 	PATCH WIDTH: Enter the width of the patch to be
!B 		maintained along the longest section,
!B 		(the distance between control points).
!B
!B 	PICK CONTOUR #: Pick the contours in order.
!B 		The actual point picked on the contour determines
!B 		the direction of the surface created.
!B
!C NOTES:
!C
!C 	The Equal Arc Length Nurb Blend is not a surface to be used when
!C 	the number of control points is very high.  The time to calculate
!C 	the surface would be quite long.
!C 	This would be a good surface to use when blending to get a smooth
!C 	surface where it is not critical to pass through the points.
!C
!C 	The patch width must be smaller than any detail on the surface
!C 	represented.  For example, if one of the cross sections has a .5 inch
!C 	radius, the patch width should be no larger than 60% of the radius or
!C 	.3 inches, in this case.
!C 	This surface is not very good for representing a surface with a lot
!C 	of detail because of the small patch width required.
!C

Stat=ChangeLabelStr("ScriptNameStatus","Function: equal arc length nurb blend ")

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

ActivateUndo
Bezier_surf= WsFalse
IF ARGC<2 THEN
        Bezier_surf= WsFalse
ELSE
        Bezier_surf= VAL(ARGV(1))
END IF

Active_workplane=0
Work=CurrentWorkplane
IF ValidGeometry(Work) THEN Active_workplane=1

Patch_width=NamedVarVal("3D Default Patch",Ws3DSystemVars,0.5)

Blend_loop:!

StdWorkplane

Group=CreateGroup("TEMP")

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Patch_width)
Patch_width=GetValue("PATCH WIDTH",Answer$)
IF ExitScript(Destination$) THEN Leave

Cont_count=1
Pick_loop: !
Stat=SetInputFormat("a1",",P,")
Stat=SetPickMask(WsPickNoSurf)
Contour=PickGroupEnt("PICK CONTOUR #"&VAL$(Cont_count)&", Proceed ",0,Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$="P" THEN Blend_ents
IF NOT ValidGeometry(Contour) THEN Pick_loop

Stat=Highlight(Contour,WsPickPen,WsDirArrowOff)
Stat=AddToGroup(Group,Contour)
Cont_count=Cont_count+1
GOTO Pick_loop

Blend_ents: !
Grp_count=GroupCount(Group)
Surf1=ArcLenBlendSurf(WsNurbSurfEnt,Group,"BLEND",Patch_width,Bezier_surf)

ActivateUndo
Stat= AdvanceUndoNumber("nurb surface")
Stat= AddItemToUndo(WsUBCreateMode,Surf1)

Stat=DeleteEntity(Group)

GOTO Blend_loop

Leave:!
Stat=SetPickMask(WsPickGeometry)
Stat=DeleteEntity(Group)
IF Active_workplane THEN
	Stat=SetWorkplane(Work)
ELSE
	StdWorkplane
END IF
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END
