
! script name: pkgroups.d/pkcreatefacegrp
! solids: create a parasolids group of faces

!A
!A NAME:
!A
!A 	Create Face Group
!A
!A DESCRIPTION:
!A
!A 	This script makes a parasolids group of faces. This group is
!A	part of the solid model and may be understood by any system which
!A	can read a parasolid file. The created group will be colored to
!A	the current color.
!A
!B INSTRUCTIONS:
!B
!B	FEATURE DESCRIPTION : Give a description of the group to be created.
!B
!B	PICK FACES: Make group, Unpick ,Clear
!B
!B NOTE:
!B
!B	Avoid placing an entity in more than one group.
!B
!B	Imported files may already have groups. Confusion may result
!B	if the user is unaware of this. The user might wish to remove all
!B	groups before starting on an imported file.
!B
!# see also - htdocs/help.d/pkgroups.htm
!# see also - htdocs/help.d/parasolids.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: make face group ")

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

ActivateUndo

Pick_color=2

Stat= GLPlotOn
Start:!

Stat=SetInputFormat("a99","",WsFalse)
Stat=GetValue("FEATURE DESCRIPTION",Descr$)
IF (ExitScript(Destination$)) THEN Leave
IF Descr$="CANCEL" THEN Leave

Num_faces= 0
Mark_group=CreateGroup("TEMPGROUP")

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

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

IF Num_faces= 99 THEN Start
IF NOT WPKIsEntity(E1) THEN Face_loop
Body= WPKParentBody(E1)

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

Make_group:!
WPKClearErrorFlag
Stat= DeleteGroup(Mark_group,WsTrue)


WPKClearErrorFlag
E2= WPKCreateGroup(Body,WsPKFaceEnt,Num_faces,Face_array)
Stat= WPKSetFeature(E2,WsPKFaceFeature)
Stat= WPKSetFeatureDescr(E2,Descr$)
Pen_color= CurrentColor
IF Pen_color THEN Stat= WPKColorEntity(E2,Pen_color)

ActivateUndo
Stat= AdvanceUndoNumber("create face group")
Stat= AddItemToUndo(WsUBPKSessionMark)
WPKErrorCheck
RETURN


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