 
! script name: amo.d/ taskzonetable
! topic: Amo tasks work zone table.

!A
!A NAME:
!A
!A 	Process Table
!A
!A DESCRIPTION:
!A
!A 	Makes a table of tasks and workzones. Used as a pre-processor
!A	for Amo execute.
!A

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

DIM Answer$[256]
DIM Destination$[256]
DIM Dir$[256],Namelist$[32000],Namelist2$[32000]
DIM Toolname$[256],Next_name$[256]

DeActivateUndo
WsAmoData= 23051
WsEventData= 12345

Method=NamedVarVal("amo direction",WsToolVars,0.0)
Use_tools=NamedVarVal("use tool numbers",WsAmoVars,WsTrue)
Init_tool=NamedVarVal("initial tool number",WsAmoVars,1)
Tool_inc=NamedVarVal("tool number increment",WsAmoVars,1)

Use_tool_table= 1

Task_ent= FindUserData("AMO OPERATIONS",WsTaskPacket)
IF ValidGeometry(Task_ent) THEN
	Tasks= PropGrpFromFields(Task_ent,"Number tools:","Tool ",1,WsToolData,WsEventData)
ELSE
	Tasks= FindNamedGrp("AMO OPERATIONS")
END IF
IF NOT ValidGeometry(Tasks) THEN Leave

Material=FindUserData("MATERIAL",WsMaterial)
IF NOT ValidGeometry(Material) THEN
	Get_material:!
	Stat= NamedVarStr("material dir",WsSystemVars,"/usr/weber/util/tooldata/materials/",Dir$)
	Stat=DirectoryNames(Dir$,"*",Namelist$)
	Stat= AlphabeticalOrder(Namelist$,",",WsAscending,Namelist2$)
	Stat=GeneralListBox("MATERIALS","MATERIAL SELECTED",Namelist2$)
	Stat=SetInputFormat("a99","")
	Stat=GetValue("INPUT MATERIAL FILE NAME",Answer$)
	LowerSelectBox
	IF ExitScript(Destination$) THEN Leave
	IF Answer$="CANCEL" THEN Leave
	Material=ReadUserData(WsMaterial,"MATERIAL",FileNameString(Dir$,Answer$))
	IF NOT ValidGeometry(Material) THEN Get_material
END IF

Pc= PointXYZ(0,0,0)
Zonelist= FindUserData("AMO WORK ZONES",23051)
Amo_table= AmoTasksZonesTable(Tasks,Zonelist,Pc,Method)
IF NOT ValidGeometry(Amo_table) THEN Leave

Stat= RedimTableColumns(Amo_Table,1,WsTrue)
Stat= InsertIntoTable(Amo_Table,"Fixture",1,4)
Stat= TaskColFromWZData(Amo_Table,5,"Fixture number:")
Stat= AmoTaskTableTnums(Amo_Table,Use_tools,Init_tool)
Stat= RedimTableColumns(Amo_Table,2,WsTrue)
IF CurrentUnits= WsMetric THEN
	Stat=InsertIntoTable(Amo_Table,"Feed(mmpm)",1,6)
ELSE
	Stat=InsertIntoTable(Amo_Table,"Feed(ipm)",1,6)
END IF
Stat=InsertIntoTable(Amo_Table,"Speed(rpm)",1,7)
Material= FindUserData("MATERIAL",WsMaterial)
Stat= TaskTableFeedSpeed(Amo_Table,Material,7,6)
Stat= NameEntity(Amo_table,"Amo process table")
Stat= DeleteEntity(Pc)
Stat= CleanAmoTasksTable(Amo_table)

Leave:!
PlotOn
Stat= DeleteEntity(Pc)
IF ValidGeometry(Task_ent) THEN Stat= DeleteEntity(Tasks)
IF (NOT LEN(Destination$)) THEN
         LOAD "typecontrol"
ELSE
         LOAD Destination$
END IF
END
