
! script name: vtools.d/readpinchtools
! var_topic: read data file for specified pinch turn tool

!A
!A NAME:
!A
!A 	PINCH-TURN TOOLS	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will create two tools tool variationally
!A	for pinch-turning tfrom a data file.
!A
!A
!B INSTRUCTIONS:
!B
!B 	INPUT MATERIAL FILE NAME: The selection box with the available
!B 		list of MATERIALS will appear for a selection to be made.
!B
!B	CHOOSE PINCH-TURN PAIR: Choose the pinch-turn pair to be used.
!B		This choice is an info packet that contains the file names
!B		of the two tools to be read into the system.

stat=ChangeLabelStr("ScriptNameStatus","Function: select lathe tool from library ")

DIM Destination$[256],Answer$[256]
DIM Name$[256],File_name$[256]
DIM Namelist$[32000],Namelist2$[32000],Default_dir$[256]
DIM Dir$[256],Class_dir$[256]
DIM Prop_dir$[512],Prop_class$[256]
DIM Prop_file$[256]

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

Var_object=CheckVarObject
IF ExitScript(Destination$) THEN Leave

ActivateUndo
Get_material:!

Material=FindUserData("MATERIAL",WsMaterial)
IF NOT ValidGeometry(Material) THEN

	Stat= NamedVarStr("material dir",WsSystemVars,"/usr/weber/util/tooldata/materials/",Dir$)
        Stat=DirectoryNames(Dir$,"*",Namelist$)
	Stat= AlphabeticalOrder(Namelist$,",",WsAscending,Namelist2$)
        Stat=GeneralListBox("MATERIALS","SELECTION",Namelist2$)

        Stat=SetInputFormat("a99","")
        Stat=GetValue("INPUT MATERIAL FILE NAME",Answer$)
        IF (ExitScript(Destination$)) THEN Leave
        IF Answer$="CANCEL" THEN Leave
        File_name$= FileNameString(Dir$,Answer$)

        Name$="MATERIAL"

        Material=ReadUserData(WsMaterial,Name$,File_name$)
        IF NOT ValidGeometry(Material) THEN Get_material

END IF

Units= CurrentUnits
Default_dir$= "/usr/weber/util/tooldata/ltools_in/"
Stat= NamedVarStr("ltools dir",WsSystemVars,Default_dir$,Dir$)

Start:!
Class_dir$= "PinchTurnTools"
Prop_class$= "PinchTurnTools"
Answer$= FileNameString(Prop_dir$,Class_dir$)

Ask_file:!
Stat=DirListBox(FileNameString(Prop_dir$,Class_dir$),"*","TOOLS","TOOL SELECTED",WsAscending)
File_name:stat= SetInputFormat("a99","")
Stat= GetValue("CHOOSE PINCH-TURN PAIR ",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$="CANCEL" THEN Leave
Prop_file$= Answer$
File_name$= FileNameString(Prop_dir$,Class_dir$,"/",Answer$)

Id_number=GetExtUserValue(File_name$,"Class id number:")
Name$=ExtUserDataStr(File_name$,"Name:")
LowerSelectBox

Make_tool_record:!
RecordFunctionOn
Stat= SetRecDelLastExec
Stat=RecordDescr(Prop_class$&" :"&Prop_file$)
V1= StringConstant(Prop_dir$)
V2= StringConstant(Name$)
V3= StringConstant(Class_dir$)
V4= StringConstant(Prop_file$)
V5= StringConstant(FileNameString(V1,V3,V4))
Prop_ent= ReadUserData(WsMiscData,V2,V5,WsTrue)
V1= StringConstant(Dir$)
V2= StringConstant("Tool directory 1:")
V3= StringConstant("Tool 1:")
V4= StringConstant("Tool directory 2:")
V5= StringConstant("Tool 2:")
V6= StringConstant(UserDataStr(Prop_ent,V2))
V7= StringConstant(UserDataStr(Prop_ent,V3))
V8= StringConstant(UserDataStr(Prop_ent,V4))
V9= StringConstant(UserDataStr(Prop_ent,V5))
V10= StringConstant(FileNameString(V1,V6,V7))
V11= StringConstant(FileNameString(V1,V8,V9))
Tool_ent1= ReadUserData(WsToolData,V7,V10)
Tool_ent2= ReadUserData(WsToolData,V9,V11)
Stat= NameEntity(Tool_ent1,ToolIdName(Tool_ent1))
Stat= NameEntity(Tool_ent2,ToolIdName(Tool_ent2))
Stat=PutToolFileName(Tool_ent1,V10)
Stat=PutToolFileName(Tool_ent2,V11)
Stat= DeleteEntity(Prop_ent)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(Tool_ent1) OR NOT ValidGeometry(Tool_ent2) THEN
        DelLastVarRecord
ELSE
        ActivateUndo
        Stat= AdvanceUndoNumber(Prop_file$)
        Stat= AddItemToUndo(WsUBCreateMode,Tool_ent1)
        Stat= AddItemToUndo(WsUBCreateMode,Tool_ent2)
        Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF

GOTO Start

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

