
! script name: vcontours.d/makeboundary
! var_topic: make a boundary from exterior and interior contours

!A
!A NAME:
!A
!A 	Make Boundary	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A	This script make a boundary entity from the exterior contour and
!A 	the interior islands.
!A
!B INSTRUCTIONS:
!B
!B 	PICK EXTERIOR CONTOUR: Pick the exterior boundary of the boundary.
!B 		The contour had to be created by types or by auto link.
!B
!B 	NUMBER OF ISLANDS: Enter the number of interior islands.
!B
!B 	PICK ISLAND # : Pick the interior islands.  The island contour(s)
!B 		had to be created by types or by auto link.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: make boundary ")

DIM Destination$[256]
DIM Answer$[256]
DIM Boundary_name$[256]
DIM Fill_name$[256]
DIM Contour$[256]
DIM Islands$[256]
DIM Isle_name$[256]

Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave

DeActivateUndo
Fill_boundary=1
Highlight_color= 3
Stat= SetDefaults(WsSelectedEntPen,Highlight_color)

Boundary_loop:!
Contour=PickGroupEnt("PICK EXTERIOR CONTOUR")
IF (ExitScript(Destination$)) THEN Leave
IF (NOT ValidDependency(Contour)) THEN Boundary_loop
Stat= EntityNameCheck(Contour,Contour$)

Closed=IsContClosed(Contour)
IF NOT Closed THEN Boundary_loop
Stat= SetSelectedFlag(Contour,WsTrue)
Stat= PlotEntity(Contour)

Stat=SetInputFormat("n0","")
Nisles=GetValue("NUMBER OF ISLANDS",Answer$)
IF (ExitScript(Destination$)) THEN Leave

Islands=CreateGroup("ISLANDS")
FOR I=1 TO Nisles
Pick_isle: Isle=PickGroupEnt("PICK ISLAND #"&VAL$(I))
	IF (ExitScript(Destination$)) THEN Leave
	IF (NOT ValidDependency(Isle)) THEN Pick_isle
	Stat=AppendToGroup(Islands,Isle)
	Stat= SetSelectedFlag(Isle,WsTrue)
	Stat= PlotEntity(Isle)
NEXT I


IF Fill_boundary THEN
	Fill_pen= CurrentColor
ELSE
	Fill_pen= -1
END IF
IF Fill_pen=0 THEN Fill_pen= 18

Stat=SetCurrentColor(Pen_color)
Stat= GenerateVarName(WsBoundaryEnt,Boundary_name$)
Stat= GenerateVarName(WsAreaFillEnt,Fill_name$)
RecordFunctionOn
Stat= RecordDescr("BOUNDARY: Exterior and Interior curves")
Stat= NullReference(Contour$)
Isles=CreateGroup("")
RecordFunctionOff
FOR I= 1 TO Nisles
        Isle= GroupElement(Islands,I)
        Stat= EntityNameCheck(Isle,Isle_name$)
        RecordFunctionOn
        Stat= AppendToGroup(Isles,Isle_name$)
        RecordFunctionOff
NEXT I
RecordFunctionOn
V1= FreeParameter("Fill pen",Fill_pen)
Boundary1= MakeBoundary(Contour$,Isles,Boundary_name$)
Fill1= FillBoundary(Boundary1,V1)
Stat= NameEntity(Boundary1,Boundary_name$)
Stat= NameEntity(Fill1,Fill_name$)
RecordFunctionOff
CloseVarRecord

Stat= SetSelectedFlag(Boundary1,WsFalse)
Stat= PlotEntity(Boundary1)


GOTO Boundary_loop

Leave:!
UnSelectAll
Stat=DeleteEntity(Islands)
Stat=SetInputFormat("n4","")
IF (NOT LEN(Destination$)) THEN
	  LOAD "typecontrol"
ELSE
	  LOAD Destination$
END IF
END
