
! script name: vsurfaces.d/nurbarcblend
! var_topic: construct nurb surface using equal arc length

!A
!A NAME:
!A
!A 	Equal Arc Length Nurb Blend	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will make a nurb surface.  The sections do not have to
!A 	have the same number of elements.  The longest section and the patch
!A 	width will determine the number of arcs used to create the nurb
!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 nurb blend will not
!A 	necessarily give the best surface, the equal elements may be a better
!A 	selection in some instances, for example, when radii and the same
!A 	number of elements on each section are involved.
!A
!B INSTRUCTIONS:
!B
!B 	PATCH WIDTH: Enter the width of the patch to be maintained along the
!B 		longest section.
!B
!B 	PICK CONTOUR # : Pick the contours in order.  The actual point picked
!B 		on the contour determines the direction of the surface created.
!B

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


DIM Answer$[256]
DIM Destination$[256]
DIM Contour$[256]
DIM Name$[256]
DIM Patch_var$[256]


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

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

Blend_loop:!

Group= CreateGroup("TEMP")

stat= SetInputFormat("n4=","")
stat= SetEqualsValue(Patch_width)
Patch_width= GetValue("PATCH WIDTH",Answer$)
IF (ExitScript(Destination$)) THEN Leave
No_patch_var= LastVariableInput(Patch_var$)



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
IF NOT ValidDependency(Contour) THEN Pick_loop

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

Blend_ents: !

Num_elements= GroupCount(Group)
Stat= GenerateVarName(WsNurbSurfEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("CUBIC SURFACE: equal element")
Stat= SetRecDelLastExec
Egroup= CreateGroup("Cross sections")
FOR I=1 TO Num_elements
        RecordFunctionOff
        E1= GroupElement(Group,I)
        Stat= EntityNameCheck(E1,Element$)
        IF ValidDependency(E1) THEN
                RecordFunctionOn
                Stat= AddToGroup(Egroup,Element$)
                RecordFunctionOff
        END IF
NEXT I
RecordFunctionOn
IF No_patch_var THEN
	V1= FreeParameter("Patch width",Patch_width)
	Surf= ArcLenBlendSurf(WsNurbSurfEnt,EGroup,"BLEND",V1)
ELSE
	Surf= ArcLenBlendSurf(WsNurbSurfEnt,EGroup,"BLEND",Patch_var$)
END IF
Stat= NameEntity(Surf,Name$)
Stat= DeleteEntity(Egroup)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

stat= DeleteEntity(Group)
stat= DeleteEntity(EGroup)
IF NOT ValidGeometry(Surf) THEN
	DelLastVarRecord
ELSE
ActivateUndo
Stat= AdvanceUndoNumber("nurb surf")
Stat= AddItemToUndo(WsUBCreateMode,Surf)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
GOTO Blend_loop

Leave:!
stat= DeleteEntity(Group)
stat= DeleteEntity(EGroup)
Stat= SetPickMask(WsPickAll)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
