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

!A
!A NAME:
!A
!A 	TURNING PROCESS TABLE: Amo tasks Work zone table.
!A
!A DESCRIPTION:
!A
!A 	Makes a table of tasks, workzones,feeds and speeds. 
!A	Used as a pre-processor	for Amo execute.
!A	The Process table gives the user final control over the order
!A	in which tools are processed as well as control over feeds and speeds.
!A
!A~ image location - images/processtable2.jpg
!A
!A	The Process Table is created in a variational record. Likewise
!A	changes to the Process Table are recorded in variational records.
!A	The Process Table should come after all machining operations
!A	in the variational program. If you wish to add new machining
!A	operations to a program that already contains a Process Table,
!A	The best proceedure is to either delete the Process Table records
!A	or to move these records to end of the variational program.
!A	If the user intends to make extensive use of the Process Table,
!A	he or she should familiarize themselves with the fundamentals
!A	of variational programming.


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]
DIM Point$[512]

DeActivateUndo
E1= FindNamedEntity("Amo process table")
IF ValidGeometry(E1) THEN
	IF ValidDependency(E1) THEN
		Stat= MessageFileBox("/usr/weber/database/messages/previousrun","ERROR")
		GOTO Leave
	ELSE
		Stat= MessageFileBox("/usr/weber/database/messages/run_in_non_VDM","ERROR")
		Stat= SetInputFormat("a1=",",Y,L,")
		Stat= SetEqualsValue(0,"Y")
		Stat= GetValue("Delete previous table  Yes or Leave ",Answer$)
		IF ExitScript(Destination$) THEN Leave
		IF Answer$= "Y" THEN Stat= DeleteEntity(E1)
		IF Answer$= "L" THEN Leave
	END IF
END IF
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,101)
Tool_inc=NamedVarVal("tool number increment",WsAmoVars,101)

Use_tool_table= 1

Task_ent= FindUserData("AMO OPERATIONS",WsTaskPacket)
IF NOT ValidGeometry(Task_ent) THEN
	Tasks= FindNamedGrp("AMO OPERATIONS")
	IF NOT ValidGeometry(Tasks) THEN Leave
END IF
Zonelist= FindUserData("AMO WORK ZONES",WsAmoData)

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

Center_point:stat= SetInputFormat("n4","")
E1=PickEntity("LOCATION")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E1) THEN Center_point
Stat= EntityNameCheck(E1,Point$)
T1= LastPickPara
Pick_return1= CurrPickReturn

Units= CurrentUnits
RecordFunctionOn
Stat= RecordDescr("TABLE: amo process table")
SELECT Pick_return1
CASE WsGeometryEnd
        Pc= ParameterReturnPt(Point$,T1,WsGeometryEnd)
CASE WsGeometryMid
        Pc= ParameterReturnPt(Point$,T1,WsGeometryMid)
CASE WsGeomCenter
        Pc= ParameterReturnPt(Point$,T1,WsGeomCenter)
END SELECT
V1= StringConstant("Amo process table")
V2= StringConstant("AMO OPERATIONS")
V3= StringConstant("Fixture")
V4= StringConstant("Fixture number:")
V5= FreeParameter("Method",NamedVarVal("amo direction",WsToolVars,0.0))
V6= FreeParameter("Tool numbers",Use_tools)
V7= FreeParameter("Initial tool",Init_tool)
! V8= FreeParameter("Increment",Tool_inc)
SELECT Units
CASE WsMetric
	V9=StringConstant("Feed(mmpm)")
	V11=StringConstant("Feed(mmpr)")
	V12=StringConstant("Speed(smpm)")
	V25=StringConstant("Turn(smpm)(")
CASE ELSE
	V9=StringConstant("Feed(ipm)")
	V11=StringConstant("Feed(ipr)")
	V12=StringConstant("Speed(sfpm)")
	V25=StringConstant("Turn(sfpm)(")
END SELECT
V10=StringConstant("Speed(rpm)")
V26=StringConstant(")")
V27=StringConstant(":")
Stat=RemoveDupTools
RecordFunctionOff
Task_ent= FindUserData(V2,WsTaskPacket)
IF ValidGeometry(Task_ent) THEN
	RecordFunctionOn
	V30=StringConstant("Number tools:")
	V31=StringConstant("Tool ")
	Task_ent= FindUserData(V2,WsTaskPacket)
	G1=PropGrpFromFields(Task_ent,V30,V31,1,WsToolData,WsEventData)
	RecordFunctionOff
ELSE
	RecordFunctionOn
	G1= FindNamedGrp(V2)
	RecordFunctionOff
END IF
RecordFunctionOn
Zonelist= FindUserData("AMO WORK ZONES",WsAmoData)
Amo_table= AmoTasksZonesTable(G1,Zonelist,Pc,V5)
RecordFunctionOff
IF NOT ValidGeometry(Amo_table) THEN
	CloseVarRecord
	DelLastVarRecord
	GOTO Leave
END IF
RecordFunctionOn
Stat=AmoTaskTableTnums(Amo_Table,V6,V7)
Stat=RedimTableColumns(Amo_Table,2,WsTrue)
Stat=InsertIntoTable(Amo_Table,V11,1,5)
Stat=InsertIntoTable(Amo_Table,V12,1,6)
Stat=RedimTableColumns(Amo_Table,2,WsTrue)
Stat=InsertIntoTable(Amo_Table,V9,1,7)
Stat=InsertIntoTable(Amo_Table,V10,1,8)
Material= FindUserData("MATERIAL",WsMaterial)
Stat=TaskTableFeedSpeed(Amo_Table,Material,8,7)
Stat= NameEntity(Amo_table,V1)
RecordFunctionOff
IF ValidGeometry(Task_ent) THEN
	RecordFunctionOn
	Stat= DeleteEntity(G1)
	RecordFunctionOff
END IF
RecordFunctionOn
Stat= DeleteEntity(Pc)
Stat= CleanAmoTasksTable(Amo_table)
RecordFunctionOff
CloseVarRecord
Stat= PlotEntity(Amo_table)

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