
! script name: parasolids.d/edgechamfer
! solids: set blend chamfer on an edge

!A
!A NAME:
!A
!A 	Blend: Chamfer
!A
!A DESCRIPTION:
!A
!A 	This script sets a blend chamfer on an edge.
!A
!A~ image location - images/pkchamfer.gif
!A
!B INSTRUCTIONS:
!B
!B	PICK EDGE: Fix, Propagate, New chamfer, Unpick ,Restore: Select the
!B 		edges which will receive the chamfer.  Different edges may have
!B 		different chamfers.  When all the desired edges have been
!B 		selected the chamfers must be either fixed or propagated to
!B 		become effective.  Fixing just puts chamfers on the edges
!B 		selected.  Propagate will cause tangent connecting edges to also
!B 		be chamfered. You cannot propagate from one chemfer size to
!B 		a different chemfer size.
!B		
!C NOTE:
!C
!C	It may be possible that some chamfers which do not work properly
!C	when in propagate mode will work if each individual edge is
!C	selected and then are collectively fixed.
!C
!# see also - htdocs/help.d/parasolids.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: set edge chamfer ")

OPTION BASE 1
DIM Destination$[256]
DIM Answer$[256]
REAL Edge_array(100,2)


Start_color= 3
End_color= 4
Pick_color= 2

Chamfer_len=NamedVarVal("solid chamfer length",WsPKSolidsVars,0.0)
Stat= GLPlotOn
Start:!
Propagate= WsFalse
GOSUB Ask_length

Group=CreateGroup("TEMPGROUP")
Num_edges= 0
Edge_loop:!
Stat=SetInputFormat("a1",",F,U,N,R,P,")
E1=WPKPickEntity("PICK EDGE: Fix, Propagate, New chamfer, Unpick ,Restore ",WsPKPickEdge,Answer$)
IF (ExitScript(Destination$)) THEN Leave

SELECT Answer$
CASE "P"
	Propagate= WsTrue
	GOSUB Fix_blends
	GOTO Start
CASE "F"
	GOSUB Fix_blends
	GOTO Start
CASE "N"
	GOSUB Ask_length
	GOTO Edge_loop
CASE "U"
        Num_edges= Num_edges-1
        IF Num_edges<0 THEN Num_edges=0
        N1= GroupCount(Group)
        E1= GroupElement(Group,N1)
        Stat=RemoveFromGrp(Group,N1)
        Stat= DeleteEntity(E1)
        PlotAll
        GOTO Edge_loop
CASE "R"
        Stat= DeleteGroup(Group,WsTrue)
        PlotAll
        GOTO Start
END SELECT
IF Num_edges= 99 THEN Start

IF NOT WPKIsEntity(E1) THEN Edge_loop
Num_edges= Num_edges+1
Edge_array(Num_edges,1)= WPKEntityTag(E1)
Edge_array(Num_edges,2)= Chamfer_len
Pt= ParameterPt(E1,0.5)
Stat= SetColor(Pt,Pick_color,WsTrue)
Stat= AddToGroup(Group,Pt)
GOTO Edge_loop

Fix_blends:!
	Stat= DeleteGroup(Group,WsTrue)
	FOR I= 1 TO Num_edges
		Edge1= Edge_array(I,1)
		Chamfer_len= Edge_array(I,2)
		Stat= WPKEdgeChamfer(Edge1,Chamfer_len,Chamfer_len,Propagate)
	NEXT I
	Stat= WPKFixBlends(Edge1,Propagate)
	WPKClearErrorFlag
	ActivateUndo
	Stat= AdvanceUndoNumber("edge chamfer")
	Stat= AddItemToUndo(WsUBPKSessionMark)
	WPKErrorCheck
RETURN

Ask_length: !
Stat= SetEqualsValue(Chamfer_len)
Stat=SetInputFormat("n4=","")
Chamfer_len=GetValue("CHAMFER LENGTH")
IF ExitScript(Destination$) THEN Leave
V1=CreateVariable("solid chamfer length",WsPKSolidsVars,Chamfer_len)
RETURN


GOTO Ploop

Leave:!
Stat= DeleteGroup(Group,WsTrue)
Stat=SetPickReturn(WsGeometryEnd)
Stat=SetInputFormat("n4","")
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
