
! script name: vsurfaces.d/varcross
! var_topic: construct variable cross section surface

!A
!A NAME:
!A
!A 	Variable Cross Section	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will make a variable cross section surface.
!A	At every point of the drive contour, a cross section
!A	is created which is a linear blend of the starting and
!A	ending cross sections.
!A	The starting and ending cross sections must be placed
!A	at the start and end points respectively of the drive
!a	contour.
!A
!B INSTRUCTIONS:
!B
!B 	U PATCH WIDTH: Enter the width of the patch to be used along
!B		       the cross section contours.
!B
!B 	V PATCH WIDTH: Enter the width of the patch to be used along
!B		       the drive contour.
!B
!B 	PICK DRIVE CONTOUR : Pick the generating contour.
!B
!B 	PICK STARTING CROSS SECTION : Pick the constant cross section.
!B
!B 	PICK ENDING CROSS SECTION : Pick the constant cross section.
!B
!B	
!C NOTES:
!C	The starting and ending cross sections must have
!C	the same number of elements.
!C
!C	The patch widths need not match small radii. The surface
!C	will automatically be created width a minimum number of
!C	patches on small radii. Small splines however will require
!C	consideration in patch size.
!C
!C	The optimum workplane for a variable cross section is the
!C	workplane of the drive contour. Most other workplanes will
!C	give an equivalent surface, but in some workplanes the 
!C	surface may not be generated, or it may give undesirable
!C	results.
!C
!C      The drive contour must not ever become perpendicular to
!C      the workplane. If this occurs the orientation of the
!C      cross section becomes confused.
!C
!C	The U contours of the variable cross section surface are the
!C	cross sections.
!C	The V contours are the contours generated along the drive
!C	contour.
!C
!C

stat=ChangeLabelStr("ScriptNameStatus","Function: variable cross section ")

DIM Answer$[256]
DIM Destination$[256]
DIM Contour$[256]
DIM Cross_section1$[256]
DIM Cross_section2$[256]
DIM Upatch_var$[256]
DIM Vpatch_var$[256]
DIM Name$[256]

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

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

Uwidth= Patch_width
Vwidth= Patch_width
Blend_loop:!

stat= SetInputFormat("n4=","")
stat= SetEqualsValue(Uwidth)
Uwidth= GetValue("U PATCH WIDTH",Answer$)
IF (ExitScript(Destination$)) THEN Leave
No_upatch_var= LastVariableInput(Upatch_var$)

stat= SetEqualsValue(Vwidth)
Vwidth= GetValue("V PATCH WIDTH",Answer$)
IF (ExitScript(Destination$)) THEN Leave
No_vpatch_var= LastVariableInput(Vpatch_var$)


Pick_loop: !
Stat= SetPickMask(WsPickNoSurf)
Contour=PickGroupEnt("PICK DRIVE CONTOUR ",0)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(Contour) THEN Pick_loop
Stat= EntityNameCheck(Contour,Contour$)
Stat=Highlight(Contour,WsPickPen,WsDirArrowOff)

Pick_cross1:Stat= SetPickMask(WsPickNoSurf)
Cross_section1=PickGroupEnt("PICK STARTING CROSS SECTION ",0)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(Cross_section1) THEN Pick_loop
Stat= EntityNameCheck(Cross_section1,Cross_section1$)
Stat=Highlight(Cross_section1,WsPickPen,WsDirArrowOff)

Pick_cross2:Stat= SetPickMask(WsPickNoSurf)
Cross_section2=PickGroupEnt("PICK ENDING CROSS SECTION ",0)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(Cross_section2) THEN Pick_loop
Stat= EntityNameCheck(Cross_section2,Cross_section2$)
Stat=Highlight(Cross_section2,WsPickPen,WsDirArrowOff)

Stat= GenerateVarName(WsCubicSurfEnt,Name$)
RecordFunctionOn
Stat=SetWorkplane
Stat= RecordDescr("CUBIC SURFACE: Variable cross section")
Stat= SetRecDelLastExec
IF No_upatch_var THEN
        V1= FreeParameter("U Patch",Uwidth)
ELSE
        V1= FreeParameter("U Patch",Upatch_var$)
END IF
IF No_vpatch_var THEN
        V2= FreeParameter("V Patch",Vwidth)
ELSE
        V2= FreeParameter("V Patch",Vpatch_var$)
END IF
Surf=  VarCrossSurface(Contour$,Cross_section1$,Cross_section2$,V1,V2)

Stat= NameEntity(Surf,Name$)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(Surf) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("variable cross section")
	Stat= AddItemToUndo(WsUBCreateMode,Surf)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF

Leave:!
Stat= SetPickMask(WsPickGeometry)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
