
! script name: vpkswept.d/vpkeeswept
! var_solids: construct body by sweeping an entity along an entity

!A
!A NAME:
!A
!A 	Sweep Entity along an Entity   VARIATIONAL
!A
!A DESCRIPTION:
!A
!A	This script sweeps an entity along an entity. The resulting
!A	body is a sheet body.
!A
!A~ image location - images/pksweepcontour.gif
!A
!B INSTRUCTIONS:
!B
!B	ALIGNMENT:  Normal, Parallel 	Alignment of cross sections.
!B				
!B			N    Normal Alignment
!B			NT   Normal Alignment with twist and scale
!B			NS   Normal Alignment scale
!B			P    Parallel Alignment
!B			PT   Parallel Alignment with twist and scale
!B			PS   Parallel Alignment scale
!B
!B      PICK ENTITY TO BE SWEPT: Pick the entity to be swept. It should be
!B              defined in a plane which is normal to the sweep. It should
!B              be placed at a vertex of the sweep path.  The entity should
!B              not be a full circle or an ellipse.
!B
!B      PICK ENTITY TO SWEEP ALONG: Pick the entity defining the sweep.  This
!B              entity can be either a regular synergy geometry entity or an
!B              edge of a parasolid body.
!B
!C NOTES:
!C
!C	The resulting body cannot not be self-intersecting. Attempting to
!C	sweep a shape around a radius to small to except it will generate
!C	a self-intersecting body. A sharp corner on the sweep path will
!C	generate a mitered corner.
!C
!C	The variable swept body form can be changed the default is 2
!C			
!C		swept body form   0:   minimal topology
!C		swept body form   1:   columns
!C		swept body form   2:   grid
!C
!# see also - htdocs/help.d/parasolids.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: sweep entity along an entity ")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Contour$[256]
DIM Path$[256]
DIM Twist_var$[256]
DIM Scale_var$[256]

ActivateUndo

Stat= GLPlotOn

Swept_form=NamedVarVal("swept body form",WsPKSolidsVars,2.0)
Simplify=NamedVarVal("simplify swept body",WsPKSolidsVars,1.0)

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

Start:!
Ask_twist= 0
Ask_scale= 0
Twist_on= 0
Stat=SetInputFormat("a2=",",N,NS,NT,P,PS,PT,")
Stat=SetEqualsValue(0,"N")
Stat=GetValue("ALIGNMENT: Normal, Parallel NS NT PS PT  ",Answer$)
IF ExitScript(Destination$) THEN Leave
SELECT Answer$
CASE "N"
	Alignment= 0
	Ask_twist= 0
	Ask_scale= 0
CASE "P"
	Alignment= 1
	Ask_twist= 0
	Ask_scale= 0
CASE "NT"
	Alignment= 0
	Ask_twist= 1
	Ask_scale= 1
	Twist_on= 1
CASE "NS"
	Alignment= 0
	Ask_twist= 0
	Ask_scale= 1
	Twist_on= 1
CASE "PT"
	Alignment= 1
	Ask_twist= 1
	Ask_scale= 1
	Twist_on= 1
CASE "PS"
	Alignment= 1
	Ask_twist= 0
	Ask_scale= 1
	Twist_on= 1
END SELECT


IF Ask_twist THEN
	Stat=SetInputFormat("n4=","")
	Stat= SetEqualsValue(Twist)
	Twist=GetValue("TWIST ANGLE  ",Answer$)
	IF ExitScript(Destination$) THEN Leave
	No_twist_var= LastVariableInput(Twist_var$)
END IF
IF Ask_scale THEN
        Stat=SetInputFormat("n4=","")
        Stat= SetEqualsValue(1.0)
        Sfactor=GetValue("SCALE FACTOR  ",Answer$)
        IF ExitScript(Destination$) THEN Leave
	No_scale_var= LastVariableInput(Scale_var$)
END IF


Pick_entity:!
E1=PickEntity("PICK ENTITY TO BE SWEPT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E1) THEN Pick_entity
Stat= EntityNameCheck(E1,Contour$)
Solid_body= WsFalse

Pick_path:!
Path=PickEntity("PICK ENTITY TO SWEEP ALONG")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(Path) THEN Pick_path
Stat= EntityNameCheck(Path,Path$)

Solid_body= WsFalse

WPKClearErrorFlag
Stat= GenerateVarName("Body",Name$)
RecordFunctionOn
Stat= RecordDescr("SOLID: Sweep entity along entity")
V1= FreeParameter("Alignment",Alignment)
V2= FreeParameter("Swept form",Swept_form)
V3= FreeParameter("Solid body",Solid_body)
V4= FreeParameter("Simplify",Simplify)
IF Twist_on THEN
	IF No_twist_var THEN
        	V5= FreeParameter("Twist angle",Twist)
	ELSE
        	V5= FreeParameter("Twist angle",Twist_var$)
	END IF
	IF No_scale_var THEN
        	V6= FreeParameter("Scale factor",Sfactor)
	ELSE
        	V6= FreeParameter("Scale factor",Scale_var$)
	END IF
    	Pkbody=WPKTwistSweptBody(Contour$,Path$,V5,V6,V3,V1,V2,V4)
ELSE
    	Pkbody=WPKMakeSweptBody(Contour$,Path$,V3,V1,V2,V4)
END IF
Stat= WPKNameBody(Pkbody,Name$)
Stat= WPKSetBodyParent(Pkbody)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= WPKSolidRecordOn(Curr_record)
ActivateUndo
Stat= AdvanceUndoNumber("sweep entity along entity")
Stat= AddItemToUndo(WsUBPKSessionMark)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
WPKErrorCheck
GOTO Pick_entity

Leave:!
V2=CreateVariable("swept body form",WsPKSolidsVars,Swept_form)
V2=CreateVariable("simplify swept body",WsPKSolidsVars,Simplify)
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END
