
! script name: pkgroups.d/pkcreateedgegrp
! solids: create a parasolids group of edges

!A
!A NAME:
!A
!A 	Create Edge Group
!A
!A DESCRIPTION:
!A
!A 	This script makes a parasolids group of edges. 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 EDGES: Make group, Propagate, Unpick ,Clear: Select the edges
!B		for the group. Order is unimportant. Propagate will also
!B		include any edges which connect smoothly to the selected edges.
!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 edge group ")

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:!
Stat=SetInputFormat("a99","",WsFalse)
Stat=GetValue("FEATURE DESCRIPTION",Descr$)
IF (ExitScript(Destination$)) THEN Leave
IF Descr$="CANCEL" THEN Leave

Num_edges= 0
Mark_group=CreateGroup("TEMPGROUP")

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

SELECT Answer$
CASE "M"
	GOSUB Make_group
	GOTO Start
CASE "P"
	IF NOT Num_edges THEN Edge_loop
	GOSUB Propagate
	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

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

WPKClearErrorFlag
E2= WPKCreateGroup(Body,WsPKEdgeEnt,Num_edges,Edge_array)
Stat= WPKSetFeature(E2,WsPKEdgeFeature)
Stat= WPKSetFeatureDescr(E2,Descr$)
Stat= WPKHighlightEntity(E2,Pick_color)
Pen_color= CurrentColor
Line_type=CurrentLT
IF Pen_color OR Line_type THEN Stat= WPKColorEntity(E2,Pen_color,Line_type)

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

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

WPKClearErrorFlag
E2= WPKPropagateEdges(Num_edges,Edge_array,Angle_tol)
Stat= WPKSetFeature(E2,WsPKEdgeFeature)
Stat= WPKSetFeatureDescr(E2,Descr$)
Pen_color= CurrentColor
Line_type=CurrentLT
Stat= WPKHighlightEntity(E2,Pick_color)
IF Pen_color OR Line_type THEN Stat= WPKColorEntity(E2,Pen_color,Line_type)

ActivateUndo
Stat= AdvanceUndoNumber("create edge 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
