
! script name: vsplines.d/bscurveent
! var_topic: construct bspline spline curve ent through a group of points

!A
!A NAME:
!A
!A 	NURBS: Control points 	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script constructs a bspline curve using a group of points
!A 	as control points.
!A
!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
!B 		coordinates of the point.  NOTE: See XYZ INPUT OPTIONS.
!B
!C NOTES:
!C
!C 	To end the point input mode, enter the last point twice.
!C
!# see also - points.d/xyzinput.hlp

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

DIM Answer$[256]
DIM Destination$[256]
DIM Point$[256]
DIM Pstart$[256]
DIM Pend$[256]
DIM Name$[256]
DEG

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

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

Point_loop:!

stat= SetInputFormat("a1",",P,")
Pick_point:Pt=PickEntity("POINT #"&VAL$(Pt_count)&" , Proceed ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$= "P" THEN Make_spline
IF NOT ValidDependency(Pt) THEN Pick_point
Stat= EntityNameCheck(Pt,Point$)
Etype= EntityType(Pt)
IF Etype<> WsPointEnt THEN Point_loop

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
		Pend=Pt
		Pt_count=Pt_count+1
		GOTO Point_loop
	END IF
ELSE
	Stat=AddToGroup(Group,Pt)
	Stat=SetLastPoint(Pt,WsXyzInput)
	Stat= SetSelectedFlag(Pt,WsTrue)
        Stat= PlotEntity(Pt)
	Plast=Pt
	Pstart=Pt
	Pt_count=Pt_count+1
	GOTO Point_loop
END IF

Make_spline:!
Num_elements= GroupCount(Group)

Stat= GenerateVarName(WsBSplineEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("NURB: nurb curve ")
Stat= SetRecDelLastExec
Egroup= CreateGroup("Picked Points")
FOR I=1 TO Num_elements
	RecordFunctionOff
        Pt= GroupElement(Group,I)
        Stat= EntityNameCheck(Pt,Element$)
        IF ValidDependency(Pt) THEN
                RecordFunctionOn
                Stat= AddToGroup(Egroup,Element$)
                RecordFunctionOff
        END IF
NEXT I
RecordFunctionOn
V1= FreeParameter("Degree",3)
S1=BSplinePtGrp(Egroup,V1,3)
Stat= NameEntity(S1,Name$)
Stat=DeleteEntity(Egroup)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(S1) THEN
	DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("nurb curve")
	Stat= AddItemToUndo(WsUBCreateMode,S1)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF

Stat= SetSelectedFlag(Group,WsFalse)
Stat= PlotEntity(Group)
Stat= DeleteEntity(Group)
GOTO Group_loop


Leave:!
Stat= SetSelectedFlag(Group,WsFalse)
Stat= PlotEntity(Group)
Stat= DeleteEntity(Group)
stat= SetInputFormat("n4","")
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
