
! script name: datatable.d/shortopertbl
! topic: short operation table

!A
!A NAME:
!A
!A 	SHORT OPERATION TABLE
!A
!A DESCRIPTION:
!A
!A 	This is a shortened version of the operations table.
!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: short 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

Number= GroupCount(Oper_group)
Nr= Number+2
Nc= 3
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,"#",Table_pos,3)

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)
	   Num_tools= GetUserValue(Oper,"Number tools:")

	   Oper_count=0
	   Operation_holes= GrpByProp(Oper,WsOperation)
	   IF ValidGeometry(Operation_holes) THEN
		Holes_group= GrpByEntType(Operation_holes,WsHoleEnt)
	        IF ValidGeometry(Holes_group) THEN
			H1= GroupElement(Holes_group,1)
			Tool1= GetAssocTool(H1)
	                IF ValidGeometry(Tool1) THEN
			   Hole_locations= GrpByTool(Holes_group,Tool1)
			   Oper_count= GroupCount(Hole_locations)
			   Stat=DeleteEntity(Hole_locations)
			END IF
			Stat=DeleteEntity(Holes_group)
		END IF
	        Stat=DeleteEntity(Operation_holes)
	   END IF
       	   Stat= InsertIntoTable(Table1,Oper_count,"integer",Table_pos,3)
	   Table_pos= Table_pos+1
	END IF
NEXT I
Stat= NameEntity(table1,"OPERATION TABLE")
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= 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
