
! script name: vtools.d/milltasktable
! var_topic: make a table the tool task list and a template file.

!A
!A NAME:
!A
!A 	Mill Tasks Table		VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	Make a Table From Current Tool Task List.
!A
!B INSTRUCTIONS:
!B
!B 	TABLE LOCATION: Enter the xy location of the table.
!B

Stat=ChangeLabelStr("ScriptNameStatus","Function: make tool task table")

DIM Destination$[512]
DIM Answer$[512]
DIM A$[512]
DIM B$[512]
DIM Name$[512]
DIM Point$[512]
DIM Prop_dir$[512]
DIM Prop_class$[512]
DIM Class_dir$[512]
DIM Class_name$[512]
DIM D_label$[512]
DIM Choice$[512]
DIM Current_dir$[512]
DIM Ques$[512]

Var_object=CheckVarObject
IF ExitScript(Destination$) THEN Leave

Stat= NamedVarStr("properties dir",WsSystemVars,"/usr/weber/database/properties/",Prop_dir$)

Grid_color= 18
Entry_color= 12
Entry_text_height= GetDefault(WsTextHeight)
Entry_text_width= GetDefault(WsTextWidth)

Header_color= 17
Head_text_height= 1.2*Entry_text_height
Head_text_width= 1.2*Entry_text_width
Header_slant= TAN(20)



ActivateUndo
Start:!
Task_ent= FindUserData("AMO OPERATIONS",WsTaskPacket)
IF NOT ValidGeometry(Task_ent) THEN
	Tool_group= FindNamedGrp("AMO OPERATIONS")
	IF NOT ValidGeometry(Tool_group) THEN Leave
END IF

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


Make_record:!
Stat= GenerateVarName(WsDataTableEnt,Name$)
RecordFunctionOn
Stat= SetRecDelLastExec
Stat=RecordDescr("TABLE: Current tools ")
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(Prop_dir$)
V2= StringConstant("TableTemplates")
V3= StringConstant("milltools")
V3= StringConstant(FileNameString(V1,V2,V3))
V4= FreeParameter("Table origin",WsUpperLeft)
V5= StringConstant(":")
V6= StringConstant("AMO OPERATIONS")
RecordFunctionOff
Task_ent= FindUserData(V6,WsTaskPacket)
IF ValidGeometry(Task_ent) THEN
	RecordFunctionOn
	V7=StringConstant("Number tools:")
	V8=StringConstant("Tool ")
	Task_ent= FindUserData(V6,WsTaskPacket)
	Tool_group=PropGrpFromFields(Task_ent,V7,V8,1,WsToolData)
	RecordFunctionOff
ELSE
	RecordFunctionOn
	Tool_group= FindNamedGrp(V6)
	RecordFunctionOff
END IF
RecordFunctionOn
Tool=ReadUserData(WsToolData,V2,V3)
Stat= InsertIntoGrp(Tool_group,Tool,1)
Table1= TableFromPropGrp(Tool_group,Pc,V5,V4)
Stat= NameEntity(Table1,Name$)
Stat= DeleteTableRow(Table1,2)
Stat= DeleteEntity(Pc)
Stat= DeleteEntity(Tool)
RecordFunctionOff
IF ValidGeometry(Task_ent) THEN
	RecordFunctionOn
	Stat= DeleteEntity(Tool_group)
	RecordFunctionOff
END IF
RecordFunctionOn
V1= FreeParameter("Entry color",Entry_color)
V2= FreeParameter("Entry text width",Entry_text_width)
V3= FreeParameter("Entry text height",Entry_text_height)
V4= FreeParameter("Entry text slant",Entry_slant)
Stat= SetTableColors(Table1,0,0,V1)
Stat= TableTextSizes(Table1,0,0,V2,V3,V4)
V1= FreeParameter("Header color",Header_color)
V2= FreeParameter("Header text width",Head_text_width)
V3= FreeParameter("Header text height",Head_text_height)
V4= FreeParameter("Header text slant",Header_slant)
V6= FreeParameter("Grid color",Grid_color)
Stat= SetTableColors(Table1,1,0,V1)
Stat= TableTextSizes(Table1,1,0,V2,V3,V4)
Stat= SetColor(Table1,V6)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(Table1) THEN
        DelLastVarRecord
ELSE
        Stat= PlotEntity(Table1)
        ActivateUndo
        Stat= AdvanceUndoNumber("tool table")
        Stat= AddItemToUndo(WsUBCreateMode,Table1)
        Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
GOTO Start

Leave:!
LowerSelectBox
Stat=SetInputFormat("n4","")
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END


