
! script name: turbopost.d/workzone
! topic: TurboPost pick work zone

!A
!A NAME:
!A
!A 	PICK WORK ZONE
!A
!A DESCRIPTION:
!A
!A 	This script allows the user to choose a new work zone location.
!A	The script rotary_zero is called with the hole that defines the
!A	origin for that work zone.
!A
!B INSTRUCTIONS:
!B
!B	WORK ZONE NUMBER: Choose the work zone to orient into by name or
!B		by number.
!B
!# see also - htdocs/help.d/millturbo.htm

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

DIM Destination$[256],Answer$[256],Command$[256],A$[256]
DIM Filename$[512],Descr$[256]
DIM Namelist$[4000],Namelist2$[4000]

DeActivateUndo
CALL Convert_old_origins
WsPplane= 7746279
WsNamedComponent= 7041776

Pick_loop:!

Stat=MakeActiveCurr

Stat=CurrActionName(Command$)
Command_type=CurrActionTyp

Start:!
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

ClearAll
Stat=SetPlotWorkZones(","&VAL$(Work_zone)&",")
UpdatePlot

H1= FindZoneOrigin(WsWorkZoneOrigin,Work_zone)
IF ValidGeometry(H1) THEN
	Hnum= HoleNumber(H1)
	A$="ASSIGN: Start_hole= "&VAL$(Hnum)&"; Holestartpt"
	Stat=OutputCmdBuff(A$,0)
	Stat=OutputCmdBuff("ASSIGN: Zone_num= "&VAL$(Work_zone)&";",0)
	Stat=OutputCmdBuff(Command$,0)
ELSE
	GOTO Start
END IF

New_command:UpdateCmdFile
	Stat=SetPickMask(WsPickAll)
	Stat=SetInputFormat("n4=","")
	LOAD "turbopost.d/turbocmd"

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
