
! script name: vsurfaces.d/constcross
! var_topic: construct constant cross section surface

!A
!A NAME:
!A
!A 	Constant Cross Section	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will make a constant cross section surface.
!A	This surface is created by sweeping a cross section contour
!A	along the drive contour, maintaining the cross section
!A	normal to the drive contour.
!A	The cross section contour must be described at the start point
!A	of the drive contour in 3D position.
!A
!B INSTRUCTIONS:
!B
!B 	U PATCH WIDTH: Enter the width of the patch to be used along
!B		       the cross section contour.
!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 CROSS SECTION : Pick the constant cross section.
!B
!C NOTES:
!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 constant 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 constant 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: constant cross section ")

DIM Answer$[256]
DIM Destination$[256]
DIM Contour$[256]
DIM Cross_section$[256]
DIM Destination$[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_cross:Stat= SetPickMask(WsPickNoSurf)
Cross_section=PickGroupEnt("PICK CROSS SECTION ",0)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(Cross_section) THEN Pick_cross
Stat= EntityNameCheck(Cross_section,Cross_section$)
Stat=Highlight(Cross_section,WsPickPen,WsDirArrowOff)

Stat= GenerateVarName(WsCubicSurfEnt,Name$)
RecordFunctionOn
Stat=SetWorkplane
Stat= RecordDescr("CUBIC SURFACE: Constant 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=  ConstCrossSurface(Contour$,Cross_section$,V1,V2)

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

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