
! script name: datatable.d/opertable
! topic: operations table

!A
!A NAME:
!A
!A 	OPERATION TABLE
!A
!A DESCRIPTION:
!A
!A 	This script creates a table of operations with the 
!A 	associated tools.
!A
!B NOTES:
!B
!B 	This script is a template only. A user may copy and modify
!B 	this script to produce custom charts. Weber systems is not
!B 	responsible for customization of charts for particular needs.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: operation table ")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Group$[256]
DIM File$[256]
DIM A$[1024]
DIM B$[1024]
DIM Toolid$[256]
DIM Data$[10000]
DIM Descr$[256]
DIM Oper_name$[256]
DIM Tool_name$[256]
DIM Feedrate$[32]


ActivateUndo
Units= CurrentUnits

Grid_color= 14

Entry_color= 8
Entry_text_height= GetDefault(WsTextHeight)
Entry_text_width= GetDefault(WsTextWidth)

Header_color= 14
Header_ltype= 9
Head_text_height= 2.0*Entry_text_height
Head_text_width= 2.0*Entry_text_width
Header_slant= TAN(30)

Label_color= 8
Label_ltype= 0
Label_text_height= 1.5*Entry_text_height
Label_text_width= 1.5*Entry_text_width
Label_slant= 0


Tab$= CHR$(9)
Lf$= CHR$(10)

Units= CurrentUnits


Oper_group= UserDataGroup(WsOperation)
IF NOT ValidGeometry(Oper_group) THEN Leave
Row_count=2
Number= GroupCount(Oper_group)
FOR I= 1 TO Number
        Oper= GroupElement(Oper_group,I)
        Stat=GetUserDataName(Oper,Oper_name$)
        IF NOT Stat THEN
	   Toolgroup= OperationTools(Oper)
	   Num_tools= GroupCount(Toolgroup)
	   Row_count= Row_count+Num_tools
           Stat= DeleteEntity(Toolgroup)
	END IF
NEXT I

Nr= Row_count
Nc= 4
Table1= FindNamedEntity("OPERATION TABLE")
IF ValidGeometry(Table1) THEN
	Stat= EraseEntity(Table1)
	Stat= ReDimTableRows(Table1,Nr)
	Stat= ReDimTableColumns(Table1,Nc)
	Stat= BlankDataTable(Table1)
ELSE
Table_pos:Stat=SetInputFormat("n4","")
	Pc=XyzInput("TABLE LOCATION ",WsXyzInput)
	IF (ExitScript(Destination$)) THEN Leave
	IF NOT ValidGeometry(Pc) THEN Table_pos
	Table1= CreateBlankTable(Pc,"OPERATION TABLE",Nr,Nc,WsUpperLeft,"  ")
	Stat= DeleteEntity(Pc)
END IF

Table_pos=1
Stat= InsertIntoTable(Table1,"Synergy Operations",Table_pos,2)


Table_pos=2
Stat= InsertIntoTable(Table1,"Hole",Table_pos,1)
Stat= InsertIntoTable(Table1,"Operation",Table_pos,2)
Stat= InsertIntoTable(Table1,"Tool",Table_pos,3)
Stat= InsertIntoTable(Table1,"Depth",Table_pos,4)


Table_pos=3
Number= GroupCount(Oper_group)
FOR I= 1 TO Number
	Oper= GroupElement(Oper_group,I)
	Stat=GetUserDataName(Oper,Oper_name$)
	IF NOT Stat THEN
	   I1= (I MOD 27)
	   I2= (I DIV 27) +1
	   IF I1< 1 THEN I1=1
	   h_letter= 64+I1
	   A$= RPT$(CHR$(h_letter),I2)

	   Stat= InsertIntoTable(Table1,A$,Table_pos,1)
           Stat= InsertIntoTable(Table1,Oper_name$,Table_pos,2)

	   Toolgroup= OperationTools(Oper)
	   Num_tools= GroupCount(Toolgroup)

	   IF Num_tools>= 1 THEN
	   	Hole_count= CountPropUsage(Oper,WsOperation,WsHoleEnt)
	   	Oper_count= Hole_count/Num_tools
		Oper_count= PROUND(Oper_count,0)
		IF Oper_count THEN
			A$= VAL$(Oper_count)&" locations"
           		Stat= InsertIntoTable(Table1,A$,Table_pos+1,2)
		END IF
	   END IF

	   Data$=""
	   FOR J=1 TO Num_tools
		Tool= GroupElement(Toolgroup,J)
		Stat=GetUserString(Tool,"Tool id name:",Tool_name$)

		Depth=0
	        G1= GrpByTool(Tool)
		IF ValidGeometry(G1) THEN
		   G2= GrpByEntType(G1,WsHoleEnt)
		   IF ValidGeometry(G2) THEN
	        	H1= GroupElement(G2,1)
			Depth= EntityValue(H1,WsHoleDepth)
			Stat= DeleteEntity(G2)
		   END IF
		   Stat= DeleteEntity(G1)
		END IF
		IF LEN(Tool_name$) THEN
        	   Stat= InsertIntoTable(Table1,Tool_name$,Table_pos,3)
           	   Stat= InsertIntoTable(Table1,Depth,"decimal 4",Table_pos,4)
	   	   Table_pos= Table_pos+1
		END IF
	   NEXT J
	END IF
	IF ValidGeometry(Toolgroup) THEN 
		Stat=DeleteEntity(Toolgroup)
	END IF
NEXT I
Stat= NameEntity(table1,"OPERATION TABLE")
Stat= TableTextOrigin(Table1,0,4,WsRightCenter)
Stat= TableTextOrigin(Table1,0,3,WsCenterText)
Stat= TableTextOrigin(Table1,0,2,WsLeftCenter)
Stat= TableTextOrigin(Table1,0,1,WsCenterText)

Stat= SetTableColors(Table1,0,1,Entry_color)
Stat= SetTableColors(Table1,0,2,Entry_color)
Stat= SetTableColors(Table1,0,3,Entry_color)
Stat= SetTableColors(Table1,0,4,Entry_color)

Stat= TableTextSizes(Table1,1,0,Head_text_width,Head_text_height,Header_slant)
Stat= TableTextOrigin(Table1,1,0,WsCenterText)
Stat= SetTableColors(Table1,1,0,Header_color)
Stat= SetTableLType(Table1,1,0,Header_ltype)
   
Stat= TableTextSizes(Table1,2,0,Label_text_width,Label_text_height,Label_slant)
Stat= TableTextOrigin(Table1,2,0,WsCenterText)
Stat= SetTableColors(Table1,2,0,Label_color)
Stat= SetTableLType(Table1,2,0,Label_ltype)

Stat= SetColor(Table1,Grid_color)
Stat= PlotEntity(Table1)

ActivateUndo
Stat= AdvanceUndoNumber("operation table")
Stat= AddItemToUndo(WsUBCreateMode,Table1)

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