
! script name: vsplines.d/blendnurb
! var_topic: construct nurb between two points on two entities

!A
!A NAME:
!A
!A 	NURBS Blend	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script constructs a bspline between two points on two entities.
!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/nurbblend.jpg
!B INSTRUCTIONS:
!B
!B 	PICK FIRST ENTITY: Pick the entity that will be the start of the
!B 		blend.  The point picked will be used to determine directions
!B 		for the blend.
!B
!B 	PICK SECOND ENTITY: Pick the entity that will be the end of the
!B 		blend.  The point picked will be used to determine directions
!B 		for the blend.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: nurbs blend ")

DIM Destination$[256]
DIM Answer$[256]
DIM Name1$[256]
DIM Name2$[256]
DIM Name$[256]
DIM Weight_var$[256]
DEG

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

ActivateUndo
Highlight_color= 3
Stat= SetDefaults(WsSelectedEntPen,Highlight_color)
Weight= 1
Spline_loop:!

Pick1:E1=PickEntity("PICK FIRST ENTITY")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E1) THEN Pick1
T1=LastPickPara
U1= 0.0*(T1<= 0.50)+ 1.0*(T1> 0.5)
Stat= EntityNameCheck(E1,Name1$)
Stat= SetSelectedFlag(E1,WsTrue)
Stat= PlotEntity(E1)

Pick2:E2=PickEntity("PICK SECOND ENTITY")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E2) THEN Pick2
T2=LastPickPara
U2= 0.0*(T2<= 0.50)+ 1.0*(T2> 0.5)
Stat= EntityNameCheck(E2,Name2$)
Stat= SetSelectedFlag(E2,WsTrue)
Stat= PlotEntity(E2)

Stat=SetEqualsValue(Weight)
Stat=SetInputFormat("n4=","")
Weight=GetValue("WEIGHT",Answer$)
IF (ExitScript(Destination$)) THEN Leave

No_weight_var= LastVariableInput(Weight_var$)


Stat= GenerateVarName(WsBSplineEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("NURB: Blend")
Stat= SetRecDelLastExec

Dirpt1=ParameterPt(Name1$,T1)
Ps=ParameterPt(Name1$,U1)
Dirpt2=ParameterPt(Name2$,T2)
Pe=ParameterPt(Name2$,U2)
IF No_weight_var THEN
	V1= FreeParameter("Weight",Weight)
	S1=BSplineTwoEnt(Name1$,Ps,Dirpt1,V1,Name2$,Pe,Dirpt2,V1)
ELSE
	S1=BSplineTwoEnt(Name1$,Ps,Dirpt1,Weight_var$,Name2$,Pe,Dirpt2,Weight_var$)
END IF
Stat=DeleteEntity(Dirpt1)
Stat=DeleteEntity(Dirpt2)
Stat=DeleteEntity(Ps)
Stat=DeleteEntity(Pe)
Stat= NameEntity(S1,Name$)
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(E1,WsFalse)
Stat= PlotEntity(E1)
Stat= SetSelectedFlag(E2,WsFalse)
Stat= PlotEntity(E2)
GOTO Spline_loop

Leave:!
Stat=DeleteEntity(Ps)
Stat=DeleteEntity(Pe)
Stat=DeleteEntity(Dirpt1)
Stat=DeleteEntity(Dirpt2)
Stat= SetSelectedFlag(E1,WsFalse)
Stat= PlotEntity(E1)
Stat= SetSelectedFlag(E2,WsFalse)
Stat= PlotEntity(E2)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END

