
! script name: vdelete.d/deletewzone
! var_topic: delete work zone from current list

!A
!A NAME:
!A
!A 	Delete Named Zone	(VARIATIONAL)
!A
!A DESCRIPTION:
!A
!A 	Delete work zone is used to remove the origin point of a work zone. 
!A 	For example; Work zone 2 needs to be deleted. Delete work zone asks
!A 	for the work zone number to delete. Answer 2 or pick geometry in Work
!A 	Zone 2 (the current origin or machining geometry). Since the work zone
!A 	origin and the associations to it are being deleted, the machining
!A 	geometry already in work zone 2 will be left around. 
!A
!A 	The question: "MOVE GEOMETRY TO WORK ZONE 0, Yes OR No" 
!A 	will come up. The machining geometry can be left on work zone 2 or
!A 	moved to work zone 0. 
!A
!A 	Different scenarios, 
!A 	1)You established the work zone incorrectly and want to change it.
!A 	You can delete the work zone origin. Answer no to the move question.
!A 	Re-establish work zone #2. This way the geometry does not have to be
!A 	re-assigned to work zone 2. 
!A
!A 	2)You do not want to use work zone 2 anymore. Delete it and answer
!A 	yes to the move. This will take the geometry created in work zone 2
!A 	and put it in work zone 0. This essentially removes that geometry
!A 	from having a work zone assigned to it. The geometry can then be
!A 	re-assigned to another work zone. 
!A
!B INSTRUCTIONS:
!B
!B 	NAME ZONE TO BE DELETED: The selection box with the NAMED ZONES
!B 		available will automatically appear for a selection
!B 		to be made.
!B

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

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

DeActivateUndo
CALL Convert_old_origins
Existing_zones:!
Group= GrpOfUserProps(WsWorkZoneOrigin,WsWorkZoneOrigin)
IF NOT GroupCount(Group) THEN Leave

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

Start:!
Stat= SetInputFormat("n0a99","")
I= GetValue("WORK ZONE NUMBER ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF LEN(Answer$) THEN
        IF Answer$="CANCEL" THEN Leave
	I= NumericPrefix(Answer$)
END IF

Move_geom= 0
Stat= SetInputFormat("a1=",",Y,N,")
Stat= SetEqualsValue(0,"Y")
Stat= GetValue("MOVE GEOMETRY TO WORK ZONE 0.  Yes OR No",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$="Y" THEN Move_geom= 1

E1= GroupElement(Group,I)
Wzone= GetUserValue(E1,"Zone number:")
Stat= DeleteEntity(Group)

RecordFunctionOn
Stat= RecordDescr("ZONE: Delete work zone")
V1= FreeParameter("Zone number",Wzone)
H1= FindZoneOrigin(WsWorkZoneOrigin,V1)
Prop_ent= GetAssocEnt(H1,WsWorkZoneOrigin)
G1= GrpByProp(Prop_ent,WsWorkZoneOrigin)
IF Move_geom THEN
	V2= FreeParameter("New zone",0)
ELSE
	V2= FreeParameter("New zone",Wzone)
END IF
G2=GrpByWorkZone(Wzone)
Stat= SetWorkZone(G2,V2)
Stat= DeleteGroup(G1,WsTrue)
Stat= DeleteEntityList(Prop_ent,G2)
RecordFunctionOff
CloseVarRecord

GOTO Existing_zones

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