
! script name: pksurfaces.d/pkfillholeinsheet
! solids: fill a hole in a sheet body

!A
!A NAME:
!A
!A 	Fill a Hole in a Sheet Body
!A
!A DESCRIPTION:
!A
!A
!B INSTRUCTIONS:
!B
!B
!B NOTE:
!B
!B
!# see also - htdocs/help.d/parasolids.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: fill hole in a sheet body ")

OPTION BASE 1
DIM Destination$[256]
DIM Answer$[256]
DIM Descr$[256]
REAL Edge_array(500)

ActivateUndo

Pick_color=2

Angle_tol=NamedVarVal("solid edge propagate angle",WsPKSolidsVars,3.0)

Stat= GLPlotOn
Start:!

Num_edges= 0
Mark_group=CreateGroup("TEMPGROUP")

Edge_loop:!
Stat=SetInputFormat("a1",",F,U,C,P,")
E1=WPKPickEntity("PICK EDGES: Fill hole, Unpick ,Clear ",WsPKPickEdge,Answer$)
IF (ExitScript(Destination$)) THEN Leave

SELECT Answer$
CASE "F"
	GOSUB Fill_hole
	GOTO Start
CASE "U"
	Num_edges= Num_edges-1
	IF Num_edges<0 THEN Num_edges=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 Edge_loop
CASE "C"
	Stat= DeleteGroup(Mark_group,WsTrue)
	Stat= DeleteEntity(Ps)
	PlotAll
	GOTO Start
END SELECT

IF Num_edges>= 499 THEN Start
IF NOT WPKIsEntity(E1) THEN Edge_loop
Body= WPKParentBody(E1)

Edge1= WPKEntityTag(E1)
FOR I= 1 TO Num_edges
	IF Edge1= Edge_array(I) THEN Edge_loop
NEXT I
Num_edges= Num_edges+1
Edge_array(Num_edges)= Edge1
Pt= ParameterPt(E1,0.5)
Stat= SetColor(Pt,Pick_color,WsTrue)
Stat= AddToGroup(Mark_group,Pt)
GOTO Edge_loop

Fill_hole:!
Stat= DeleteGroup(Mark_group,WsTrue)

WPKClearErrorFlag
Stat= WPKFillHole(Body,Num_edges,Edge_array)

ActivateUndo
Stat= AdvanceUndoNumber("fill hole in sheet")
Stat= AddItemToUndo(WsUBPKSessionMark)
WPKErrorCheck
RETURN


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