
! script name: plot.d/plotbyzone
! topic: plot geometry associated with a particular work zone

!A
!A NAME:
!A
!A 	Plot By Work Zone
!A
!A DESCRIPTION:
!A
!A 	This script allows geometry associated with a particular zone
!A 	to be made visible.
!A
!A NOTES:
!A
!A	Multiple work zones may be made visible by inputting ,2,3,4, that is
!A	start with a comma and separate by commas.
!A

stat=ChangeLabelStr("ScriptNameStatus","Function: plot by work zone ")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Namelist$[32000]
DIM Namelist2$[32000]
DIM Descr$[256]
DIM Zones_str$[256]

Zones_str$="0"
CALL Convert_old_origins

Existing_zones:!
Group= GrpOfUserProps(WsWorkZoneOrigin,WsWorkZoneOrigin)
IF NOT GroupCount(Group) THEN Start

Namelist$=""
FOR I=1 TO GroupCount(Group)
        E1= GroupElement(Group,I)
        Zone_num= GetUserValue(E1,"Zone number:")
        if(Zone_num) THEN
                Descr$= UserDataStr(E1,"Description:")
                Namelist$= Namelist$&VAL$(Zone_num)&": "&Descr$&","
        END IF
NEXT I
Stat= DeleteEntity(Group)
IF LEN(Namelist$) THEN
Stat= NumericalOrder(Namelist$,",",WsAscending,Namelist2$)
Stat=GeneralListBox("WORK ZONES","zone selected",Namelist2$)
END IF


Start:!
Stat= SetInputFormat("n0a99","")
Work_zone=InputWorkZone("WORK ZONE NUMBER, current work zone= "&Zones_str$,Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF LEN(Answer$) THEN
        IF Answer$="CANCEL" THEN Leave
	IF POS(Answer$,",") THEN
		ClearAll
		Stat=SetPlotWorkZones(","&Answer$&",")
		UpdatePlot
		Zones_str$=Answer$
	ELSE
		Work_zone= NumericPrefix(Answer$)
		ClearAll
                Stat=SetPlotWorkZones(","&VAL$(Work_zone)&",")
                UpdatePlot
		Zones_str$= VAL$(Work_zone)
	END IF
ELSE
	ClearAll
        Stat=SetPlotWorkZones(","&VAL$(Work_zone)&",")
        UpdatePlot
	Zones_str$= VAL$(Work_zone)
END IF
GOTO Existing_zones

Leave:!
LowerSelectBox
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END

SUB Convert_old_origins
DIM Answer$[256]
DIM Zone_name$[256]

G1= UserDataGroup(WsWorkZoneOrigin)
IF NOT ValidGeometry(G1) THEN SUBEXIT
Num_origins= GroupCount(G1)

FOR I= 1 TO Num_origins
        E1= GroupElement(G1,I)
        IF CheckUserField(E1,"Class id number:",1) THEN Next_i
        Group1= GrpByProp(E1,WsWorkZoneOrigin)
        IF NOT ValidGeometry(Group1) THEN Next_i
        IF NOT GroupCount(Group1) THEN Next_i
	GOTO End_it
Next_i: NEXT I
Stat=DeleteEntity(G1)
SUBEXIT
End_it:	Answer$="/usr/weber/database/messages/convert_old_zones"
	Stat=MessageFileBox(Answer$,"INFORMATION")
	Stat=DeleteEntity(G1)
	Stat=DeleteEntity(Group1)
SUBEND
