
! script name: vsurfaces.d/cubicblend
! var_topic: construct cubic surface of equal elements

!A
!A NAME:
!A
!A 	Equal Elements	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will make a cubic surface.  There must be the same number
!A 	of elements on each section.
!A
!B INSTRUCTIONS:
!B
!B 	PATCH WIDTH: Enter the width of the patch to be used.
!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: cubic 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(WsCubicSurfEnt,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= EqualElementSurf(WsCubicSurfEnt,EGroup,"BLEND",V1)
ELSE
	Surf= EqualElementSurf(WsCubicSurfEnt,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("bicubic 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
