
! script name: nurbs.d/bsplinecurve
! topic: construct bspline curve between group of points

!A
!A NAME:
!A
!A 	NURBS: Control points
!A
!A DESCRIPTION:
!A
!A 	This script constructs a bspline curve using a group of points
!A      as control points.
!A 	A bspline is a rational function of fixed degree and it offers the
!A 	option of non-uniform parameterization.
!A
!A~ image location - images/NurbCurve.jpg
!B INSTRUCTIONS:
!B
!B 	CONTROL POINT #  ABS X,Y,Z: Enter the X,Y,Z coordinates of the point.
!B 		NOTE: See XYZ INPUT OPTIONS.
!B
!B NOTES:
!B
!B 	 To end the point input mode, enter the last point twice.
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: nurbs: control points ")

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

ActivateUndo
Highlight_color= 3
Stat= SetDefaults(WsSelectedEntPen,Highlight_color)
Group_loop:!
Group=CreateGroup("TEMPGROUP")
Pt_count=1

Point_loop:!

Ploop:Pt=XyzInput("CONTROL POINT #"&VAL$(Pt_count)&" ",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave

IF Pt_count>1 THEN
	Dist=DistTwoPts(Pt,Plast)
	IF (Dist>0.0001) THEN
		Stat=AddToGroup(Group,Pt)
		Stat=SetLastPoint(Pt,WsXyzInput)
		Stat= SetSelectedFlag(Pt,WsTrue)
        	Stat= PlotEntity(Pt)
		Plast=Pt
		Pt_count=Pt_count+1
		Stat= DeleteEntity(Sp)
		Sp=BSplinePtGrp(Group,3,3)
		GOTO Point_loop
	END IF
ELSE
	Stat=AddToGroup(Group,Pt)
	Stat=SetLastPoint(Pt,WsXyzInput)
	Stat= SetSelectedFlag(Pt,WsTrue)
        Stat= PlotEntity(Pt)
	Plast=Pt
	Pt_count=Pt_count+1
	GOTO Point_loop
END IF

Stat= DeleteEntity(Sp)
Sp=BSplinePtGrp(Group,3,3)
Stat=DeleteGroup(Group)
Stat=DeleteEntity(Pt)

ActivateUndo
Stat= AdvanceUndoNumber("nurb curve")
Stat= AddItemToUndo(WsUBCreateMode,Sp)
LOAD "nurbs.d/bsplinecurve"
GOTO Group_loop


Leave:!
IF ValidGeometry(Sp) THEN
	ActivateUndo
	Stat= AdvanceUndoNumber("nurb curve")
	Stat= AddItemToUndo(WsUBCreateMode,Sp)
END IF
Stat=DeleteEntity(Pt)
Stat=DeleteGroup(Group)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END

