
! script name: workzones.d/zonegroup
! topic: assign contours to work zone

!A
!A NAME:
!A
!A 	Work Zone Assign to Contour
!A
!A DESCRIPTION:
!A
!A 	This script allows contours to be assigned to a work zone.
!A
!B INSTRUCTIONS:
!B
!B 	WORK ZONE NUMBER,   current work zone= # : Enter the work zone 
!B 		number that will be assigned to the work zone selected.
!B
!B 	PICK CONTOUR TO BE ASSIGNED WORK ZONE # : Pick the contour that is
!B 		to be assigned to the work zone selected.
!B

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

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

ActivateUndo
CALL Convert_old_origins
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= "&VAL$(Work_zone),Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF LEN(Answer$) THEN
        IF Answer$="CANCEL" THEN Leave
        Work_zone= NumericPrefix(Answer$)
END IF

Ploop:!
E1=PickGroupEnt("PICK CONTOUR TO BE ASSIGNED WORK ZONE "&VAL$(Work_zone))
IF ExitScript(Destination$) THEN Leave

ActivateUndo
Stat= AdvanceUndoNumber("set work zone")
Stat= AddGroupToUndo(WsUBModifyMode,E1,1,WsTrue)

Stat=SetComponent(E1,Work_zone)

GOTO Ploop

Leave:!
Stat= DeleteEntity(Group)
LowerSelectBox
Stat=SetInputFormat("n4=","")
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
