
! script name: vdraft.d/areafill
! var_topic: fill the area inside exterior contour and outside interior islands

!A
!A NAME:
!A
!A 	Area Fill	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A	This script Fills the area inside the exterior contour and outside
!A 	the interior islands. 	
!A
!B INSTRUCTIONS:
!B
!B 	PICK EXTERIOR CONTOUR: 	Pick the Exterior boundary of the hatch area.
!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 contour had to be
!B 		created by types or by auto link.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: area fill ")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Cname$[256]
DIM Boundary$[256]
DIM Iname$[256]
DEG

RaiseColorBox

DeActivateUndo
Start:!
Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave

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

Closed=IsContClosed(Contour)
IF NOT Closed THEN Boundary_loop

Stat=SetInputFormat("n0=","")
Stat= SetEqualsValue(0)
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= EntityNameCheck(Isle,Iname$)
	Stat=AddToGroup(Islands,Isle)
NEXT I

Fill_pen= CurrentColor

Stat= GenerateVarName(WsAreaFill,Name$)
Stat= GenerateVarName(WsBoundaryEnt,Boundary$)
RecordFunctionOn
Stat= RecordDescr("DIM: Area Fill")
Stat= SetRecDelLastExec
Isles=CreateGroup("")
RecordFunctionOff
FOR I= 1 TO Nisles
	Isle= GroupElement(Islands,I)
	Stat= EntityNameCheck(Isle,Iname$)
	RecordFunctionOn
	Stat= AddToGroup(Isles,Iname$)
	RecordFunctionOff
NEXT I
RecordFunctionOn
V1= FreeParameter("Fill pen",Fill_pen)
Boundary1= Boundary(Cname$,Isles,Boundary$)
Fill1= FillBoundary(Boundary1,V1)
Stat= NameEntity(Fill1,Name$)
Stat= NameEntity(Boundary1,Boundary$)
Stat=DeleteEntity(Isles)
RecordFunctionOff
CloseVarRecord
IF NOT ValidGeometry(Fill1) THEN
        DelLastVarRecord
END IF

Stat= PlotEntity(E1)
Stat= PlotEntity(Cname$)
Stat= PlotEntity(Islands)
Stat= DeleteEntity(Islands)
GOTO Boundary_loop

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

