
! script name: 3dwrap.d/revwrapsurf
! var_topic: wraps a surface on a revolution

!A
!A NAME:
!A
!A 	Revolution Wrap Surface		VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script wraps a surface about a surface of revolution.
!A
!B INSTRUCTIONS:
!B
!B 	RADIUS OF CYLINDER: Enter the base radius
!B 		of the cylinder to be wrapped around.
!B 		This radius is used for angle calculations.
!B
!B 	STARTING ANGLE: Enter the starting
!B 		angular coordinate of the wrapped surface.
!B
!B 	PICK SURFACE TO BE WRAPPED: Pick the surface
!B 		to be wrapped.
!B
!B 	U PATCH WIDTH: Enter the width for the U patch.
!B
!B 	V PATCH WIDTH: Enter the width for the V patch.
!B
!B 	PICK REVOLUTION PROFILE CONTOUR: Pick contour
!B 		defining the profile of the surface of revolution.
!B
!C NOTES:
!C
!C 	The wrapping algorithm is as follows:
!C 	A point on the surface to be wrapped has an X,Y,Z coordinate
!C 	relative to the current workplane. The X coordinate determines
!C 	the angular displacement around the wrapping cylinder.
!C 	X=0 will be mapped into the starting angle relative to the
!C 	wrapping cylinder. X= 2*PI*R will be mapped into one full
!C 	revolution around the wrapping cylinder from the starting angle.
!C 	X= 2*PI*R*A/360 will be mapped into a point at an angle A
!C 	relative to the starting angle.
!C
!C 	The Y coordinate on the wrapping surface becomes the Y coordinate
!C 	on the wrapped surface.
!C
!C 	The Z coordinate on the wrapping surface becomes a radial displacement
!C 	from the radius of the surface of revolution.
!C 	Z=0 corresponds to the surface of revolution.
!C 	A positive Z adds to the radius. A negative Z subtracts from the radius.
!C
!C 	The wrapping surface is not a true development of the wrapped surface.
!C

Stat=ChangeLabelStr("ScriptNameStatus","Function: revolution wrap surface")

DIM Destination$[256]
DIM Answer$[256]
DIM Surface$[256]
DIM Rcontour$[256]
DIM Radius_var$[256]
DIM Astart_var$[256]
DIM Taper_var$[256]
DIM Upatch_var$[256]
DIM Vpatch_var$[256]
DIM Name$[256]


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

ActivateUndo
Tol=NamedVarVal("3D Intersect Tol",Ws3DSystemVars,0.005)
Patch_width=NamedVarVal("3D Default Patch",Ws3DSystemVars,0.5)
Uwidth=Patch_width
Vwidth=Patch_width

Ask_radius:Stat=SetInputFormat("n4=","")
Radius=InputRadius("RADIUS OF CYLINDER")
IF (ExitScript(Destination$)) THEN Leave
No_radius_var= LastVariableInput(Radius_var$)
C1= LastPickEnt
IF ValidGeometry(C1) THEN
        IF NOT ValidDependency(C1) THEN Ask_radius
        No_radius_var=0
        Stat= EntityNameCheck(C1,Radius_var$)
END IF

Astart=InputAngle("STARTING ANGLE")
IF ExitScript(Destination$) THEN Leave
No_astart_var= LastVariableInput(Astart_var$)


Ploop:!
Stat=SetInputFormat("n4","")
Stat= SetPickMask(WsPickSurfOnly)
Surface=PickEntity("PICK SURFACE TO BE WRAPPED" )
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(Surface) THEN Ploop
Stat= EntityNameCheck(Surface,Surface$)
Stat= SetPickMask(WsPickAll)

Ask_patches=IsSurfaceEntity(Surface)
IF NOT Ask_patches THEN Ploop

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

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

Etype= WsCubicSurfEnt


Stat=SetInputFormat("n4","")
Stat= SetPickMask(WsPickNoSurf)
Rcontour=PickGroupEnt("PICK REVOLUTION PROFILE CONTOUR " )
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(Rcontour) THEN Ploop
Stat= EntityNameCheck(Rcontour,Rcontour$)
Stat= SetPickMask(WsPickAll)


Stat= GenerateVarName(WsCubicSurfEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("REVOLUTION WRAP: Surface")
Stat= SetRecDelLastExec
IF No_astart_var THEN
        V2= FreeParameter("Astart",Astart)
ELSE
        V2= FreeParameter("Astart",Astart_var$)
END IF
V3= FreeParameter("Tolerance",Tol)
IF No_upatch_var THEN
	V4= FreeParameter("U Patch",Upatch)
ELSE
	V4= FreeParameter("U Patch",Upatch_var$)
END IF
IF No_vpatch_var THEN
	V5= FreeParameter("V Patch",Vpatch)
ELSE
	V5= FreeParameter("V Patch",Vpatch_var$)
END IF
IF No_radius_var THEN
	V1= FreeParameter("Radius",Radius)
	E2=RevolutionWrap(Surface$,Rcontour$,V1,V2,V3,V4,V5)
ELSE
	E2=RevolutionWrap(Surface$,Rcontour$,Radius_var$,V2,V3,V4,V5)
END IF
Stat= NameEntity(E2,Name$)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

ActivateUndo
Stat= AdvanceUndoNumber("wrap surface")
Stat= AddItemToUndo(WsUBCreateMode,E2)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
GOTO Ploop

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