
! script name: pktransform.d/pkmovefacelist
! solids: move multiple faces within a body

!A
!A NAME:
!A
!A 	Move Faces
!A
!A DESCRIPTION:
!A
!A 	This script will move multiple faces within a body.
!A
!A~ image location - images/pkmovefaces.gif
!A
!B INSTRUCTIONS:
!B
!B 	PICK FACES: Apply, Unpick ,Clear: Pick the faces.
!B
!B 	REFERENCE POINT: Input the reference point.
!B
!B 	DESTINATION POINT: Input the destination point.
!B
!C NOTES:
!C
!C      A group of faces may be moved within a body provided the
!C      intersections with the neighboring elements are simple enough.
!C      The moved faces must basically intersect the same faces that
!C      they did before the move. Faces cannot be eliminated, the moved
!C      faces cannot separate the body into multiple bodies. More things
!C      are possible with analytic surfaces than with non-analytic
!C      surfaces such as nurbs.
!C
!# see also - htdocs/help.d/parasolids.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: move multiple faces")

OPTION BASE 1
DIM Destination$[256]
DIM Answer$[256]
REAL Face_array(100)

ActivateUndo

Pick_color=2
Stat= GLPlotOn
Start:!
Num_faces= 0
Mark_group=CreateGroup("TEMPGROUP")

Face_loop:!
Stat=SetInputFormat("a1",",A,U,C,")
E1=WPKPickEntity("PICK FACES: Apply, Unpick ,Clear ",WsPKPickFace,Answer$)
IF (ExitScript(Destination$)) THEN Leave

SELECT Answer$
CASE "A"
        GOSUB Apply_transform
        GOTO Start
CASE "U"
        Num_faces= Num_faces-1
        IF Num_faces<0 THEN Num_faces=0
        N1= GroupCount(Mark_group)
	IF N1 THEN
        	E1= GroupElement(Mark_group,N1)
        	Stat=RemoveFromGrp(Mark_group,N1)
        	Stat= DeleteEntity(E1)
        	N1= GroupCount(Mark_group)
	END IF
        PlotAll
        GOTO Face_loop
CASE "C"
        Stat= DeleteGroup(Mark_group,WsTrue)
        PlotAll
        GOTO Start
END SELECT
IF Num_faces= 99 THEN Start
IF NOT WPKIsEntity(E1) THEN Face_loop

UVpoint=LastUVSurfPick(E1)
IF NOT ValidGeometry(UVpoint) THEN Face_loop
U=XPointValue(UVpoint)
V=YPointValue(UVpoint)
Stat= DeleteEntity(UVPoint)

Face1= WPKEntityTag(E1)
FOR I= 1 TO Num_faces
        IF Face1= Face_array(I) THEN Face_loop
NEXT I
Num_faces= Num_faces+1
Face_array(Num_faces)= Face1
Pt= SurfParameterPt(E1,U,V)
Stat= SetColor(Pt,Pick_color,WsTrue)
Stat= AddToGroup(Mark_group,Pt)
GOTO Face_loop

Apply_transform:!
Ps=XyzInput("REFERENCE POINT ",WsXyzInput)
IF ExitScript(Destination$) THEN Leave
Stat= SetLastPoint(Ps)

Pe=XyzInput("DESTINATION POINT",WsXyzInput)
IF ExitScript(Destination$) THEN Leave
Stat= SetLastPoint(Pe)

T1=AngleTransform(Ps,0,0,0,WsWorkplaneVals)
T2= InverseTrans(T1)
T3=AngleTransform(Pe,0.0,0.0,0.0,WsWorkplaneVals)
T4= MultTransforms(T3,T2)

Stat= DeleteGroup(Mark_group,WsTrue)
WPKClearErrorFlag
Stat=WPKTransFaceList(Num_faces,Face_array,T4)
Stat= DeleteEntityList(Ps,Pe,T1,T2,T3,T4)

ActivateUndo
Stat= AdvanceUndoNumber("move multiple faces")
Stat= AddItemToUndo(WsUBPKSessionMark)
WPKErrorCheck
RETURN

Leave:!
Stat= DeleteGroup(Mark_group,WsTrue)
Stat= DeleteEntityList(Ps,Pe,T1,T2,T3,T4)
Stat=SetInputFormat("n4","")
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END
