
! script name: pktransform.d/pknonunfmscalefaces
! solids: non uniform scale faces within a solid body

!A
!A NAME:
!A
!A 	Non Uniform Scale Faces
!A
!A DESCRIPTION:
!A
!A      This script will non uniformly scale faces within a body .
!A
!B INSTRUCTIONS:
!B
!B      PICK FACES: Apply, Unpick ,Clear: Pick the faces.
!B
!B      X SCALE FACTOR: Enter the x scale factor.
!B
!B      Y SCALE FACTOR: Enter the y scale factor.
!B
!B      Z SCALE FACTOR: Enter the z scale factor.
!B
!B      REFERENCE POINT: Input the reference point.
!B
!C NOTES:
!C
!C      Scaling faces within a body creates special problems. When
!C      the faces are scaled they often change form from analytic
!C      surfaces to nurb surfaces. Nurb surfaces are not easily extended
!C      to join with the remaining faces in the body.
!C
!C      Do not use scaling to change the diameter of a cylindrical or
!C      conical hole. Even uniform scaling will change circle edges
!C      into nurb curves.
!C
!# see also - htdocs/help.d/parasolids.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: non uniform scale faces")

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

ActivateUndo

Xscale=1
Yscale=1
Zscale=1

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:!
Stat=SetInputFormat("n4="," ")
Stat=SetEqualsValue(Xscale)
Xscale=GetValue("X SCALE FACTOR  ",Answer$)
IF (ExitScript(Destination$)) THEN Leave

Stat=SetInputFormat("n4="," ")
Stat=SetEqualsValue(Yscale)
Yscale=GetValue("Y SCALE FACTOR  ",Answer$)
IF (ExitScript(Destination$)) THEN Leave

Stat=SetInputFormat("n4="," ")
Stat=SetEqualsValue(Zscale)
Zscale=GetValue("Z SCALE FACTOR  ",Answer$)
IF (ExitScript(Destination$)) THEN Leave

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

T1= NonUnfmScaleTrans(Pc,Xscale,Yscale,Zscale)

Stat= DeleteGroup(Mark_group,WsTrue)
WPKClearErrorFlag
Stat=WPKTransFaceList(Num_faces,Face_array,T1)
Stat= DeleteEntity(Pc)
Stat= DeleteEntity(T1)

ActivateUndo
Stat= AdvanceUndoNumber("non-uniform scale faces")
Stat= AddItemToUndo(WsUBPKSessionMark)
WPKErrorCheck
GOTO Start

Leave:!
Stat= DeleteGroup(Mark_group,WsTrue)
Stat= DeleteEntity(Pc)
Stat= DeleteEntity(T1)
Stat=SetInputFormat("n4","")
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END
