
! script name: vlathetools.d/boringbar
! var_topic: Read a lathe tool holder property for a boring bar.

!A
!A NAME:
!A
!A 	Read a lathe boring bar tool holder property.  VARIATIONAL
!A
!A DESCRIPTION:
!A	
!A	This script is to be used to variationally build a tool data file.
!A	And a tool image for an boring bar.
!A	The results of this script is the insert shape as well as
!A	some of the basic lines for the holder. This is to be used as the
!A	starting point for building a tool shape.
!A
!A
!B INSTRUCTIONS:
!B
!B	INPUT TYPE OF TOOL: This script needs a template file for
!B				the tool data file. This is the type of
!B				tool to be used for a template.
!B
!B	INPUT TOOL TEMPLATE FILE NAME: The actual tool data file to be used
!B				as a template. The template file should be
!B				a basic tool file which will always be
!B				present. If the template file disapears then
!B				the resulting variational program will no
!B				longer function.
!B
!B	NEW SYNERGY TOOL NAME: This is used as a prefix with the holder name
!B				added on.
!B
!B	HOLDER CLASS DIRECTORY: Select the type of holder to be used.
!B				This menu is designed to list user
!B				property classes which have the characters
!B				BoringBar in the name. 
!B
!B	HOLDER FILE NAME:	Select the name of the user property that
!B				is to be used as the holder.
!B
!C NOTE:
!C	
!C
!# see also - vlathetools.d/latheholders.hlp

Stat=ChangeLabelStr("ScriptNameStatus","Function: lathe boring bar holder data ")

DIM Destination$[256]
DIM Answer$[256]
DIM A$[256]
DIM B$[256]
DIM Name$[256]
DIM Element$[256]
DIM Base_dir$[256]
DIM Inserts_dir$[256]
DIM Holder_class$[256]
DIM Holder_name$[256]
DIM Class_dir$[256]
DIM Class_name$[256]
DIM Filename$[256]
DIM Holder_file$[256]
DIM Group_name$[256]
DIM Pts_name$[256]
DIM Shank_name$[256]
DIM Namelist$[32000]
DIM Namelist2$[32000]
DIM D_label$[256]
DIM Choice$[256]
DIM Tdir_var$[256]
DIM Tdefault_dir$[256]
DIM Tool_dir$[256]
DIM Tool_class$[256]
DIM Tool_class_dir$[256]
DIM Tool_image_dir$[256]
DIM Tool_file$[256]
DIM Tool_name$[256]

Var_object=CheckVarObject
IF ExitScript(Destination$) THEN Leave

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

Base_dir$= FileNameString(Base_dir$,"Holders.d/BoringBars.d/")

Tdir_var$= "ltools dir"
Tdefault_dir$= "/usr/weber/util/tooldata/ltools_in/"
Stat= NamedVarStr(Tdir_var$,WsSystemVars,Tdefault_dir$,Tool_dir$)
Tool_image_dir$= "boringbars"


Start:!

Tool_type:!
D_label$="TOOL TEMPLATE TYPE DIRECTORY"
Choice$="TOOL TEMPLATE TYPE SELECTED"
Mask$="*"
Stat=DirectoryNames(Tool_dir$,Mask$,Namelist$)
Stat= AlphabeticalOrder(Namelist$,",",WsAscending,Namelist2$)
Stat=GeneralListBox(D_label$,Choice$,Namelist2$)

Stat=SetInputFormat("a99","")
Stat=GetValue("INPUT TYPE OF TOOL",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$="CANCEL" THEN Leave
Tool_class$=Answer$
Tool_class_dir$= FileNameString(Tool_dir$,Answer$)

Get_tool:!

D_label$="TOOL TEMPLATES AVAILABLE"
Choice$="TOOL TEMPLATE SELECTED"
Stat=DirectoryNames(Tool_class_dir$,Mask$,Namelist$)
Stat= AlphabeticalOrder(Namelist$,",",WsAscending,Namelist2$)
Stat=GeneralListBox(D_label$,Choice$,Namelist2$)

Stat=SetInputFormat("a99","")
Stat=GetValue("INPUT TOOL TEMPLATE FILE NAME",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$="CANCEL" THEN Start
Tool_file$= Answer$

Tool_ent= ReadUserData(WsToolData,"Template",FileNameString(Tool_class_dir$,Tool_file$))
IF NOT ValidGeometry(Tool_ent) THEN Start
Tool_name$= UserDataStr(Tool_ent,"Tool id name:")
Quadrant= GetUserValue(Tool_ent,"Tool quadrant:")
N1= POS(Tool_name$,"(")
IF N1>1 THEN
	Tool_name$= Tool_name$[1,N1-1]
	Tool_name$= TRIM$(Tool_name$)
END IF

Stat= DeleteEntity(Tool_ent)
LowerSelectBox

Stat=SetInputFormat("a99=","")
Stat= SetEqualsValue(0,Tool_name$)
Stat=GetValue("NEW SYNERGY TOOL NAME",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$="CANCEL" THEN Start
Tool_name$= TRIM$(Answer$)


New_holder:!
D_label$="HOLDER CLASSES"
Choice$="CLASS SELECTED"
Mask$= "*"
Stat=DirListBox(Base_dir$,Mask$,D_label$,Choice$,WsAscending)

Stat=SetInputFormat("a99","")
Stat=GetValue("HOLDER CLASS DIRECTORY",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$="CANCEL" THEN Leave
Answer$= TRIM$(Answer$)
Class_dir$= FileNameString(Base_dir$,Answer$)
Holder_class$= TRIM$(Answer$)

Ask_file:!
D_label$= Holder_class$
Choice$= Holder_class$&" SELECTED"
Stat=DirListBox(Class_dir$,"*",D_label$,Choice$,WsAscending)

File_name:stat= SetInputFormat("a99","")
stat= GetValue("HOLDER FILE NAME ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$="CANCEL" THEN Start
IF NOT LEN(Answer$) THEN File_name
Holder_file$= TRIM$(Answer$)
Filename$= FileNameString(Class_dir$,Holder_file$)

Id_number=GetExtUserValue(Filename$,"Class id number:")
Name$=ExtUserDataStr(Filename$,"Name:")
Class_name$=ExtUserDataStr(Filename$,"Class name:")
LowerSelectBox

Prop_dir=CreateVariable("Prop_directory",WsVariationVars,Class_dir$)
Tool_library=CreateVariable("Tool_library",WsVariationVars,Tool_class_dir$)
Holder_name=CreateVariable("Holder_name",WsVariationVars,Holder_file$)
Tool_prefix=CreateVariable("Tool_prefix",WsVariationVars,Tool_name$)
Tool_template=CreateVariable("Tool_template",WsVariationVars,Tool_file$)

Make_holder:!
Stat= GenerateVarName(WsDataStringEnt,Holder_name$)
Stat= GenerateVarName(WsGroupEnt,Group_name$)
Stat= GenerateVarName(WsGroupEnt,Pts_name$)
Stat= GenerateVarName(WsGroupEnt,Shank_name$)
RecordFunctionOn
Stat=RecordDescr("BORING BAR:"&Class_name$)
V3=StringConstant(FindNamedVar("Prop_directory",WsVariationVars))
V4=StringConstant(FindNamedVar("Holder_name",WsVariationVars))
V5= StringConstant(FileNameString(V3,V4))
Holder_ent= ReadUserData(Id_number,V4,V5,WsTrue)
Stat= NameEntity(Holder_ent,Holder_name$)
Tool_template:!
V6= StringConstant(Tool_name$)
V7= StringConstant(JoinStrings(V6,"(",V4,")"))
V8=StringConstant(FindNamedVar("Tool_library",WsVariationVars))
V9=StringConstant(FindNamedVar("Tool_template",WsVariationVars))
V10= StringConstant(FileNameString(V8,V9))
Update_tool:!
Tool_ent= ReadUserData(WsToolData,V7,V10,WsTrue)
Stat= PutUserString(Tool_ent,"Tool id name:",V7)
Stat= PutUserString(Tool_ent,"Tool image:",LWC$(VariableString(V7)))
Stat= PutUserString(Tool_ent,"Holder file:",VariableString(V5))
V11= StringConstant(JoinStrings(V6," ",V4))
V12= StringConstant(MakeNameValid(V11,WsValidFileName))
V13= StringConstant(FileNameString(Tool_image_dir$,V12))
Stat= PutUserString(Tool_ent,"Tool image file:",V13)
V13= StringConstant("Insert orientation:")
IF Obtuse_insert THEN
	V14= StringConstant("obtuse")
ELSE
	V14= StringConstant("acute")
END IF
Stat= PutUserString(Tool_ent,V13,V14)
V15= FreeParameter("Quadrant",Quadrant)
Stat= PutUserValue(Tool_ent,"Tool quadrant:",V15)
Stat= CopyFieldsIntoTool(Holder_ent,Tool_ent,WsBoringBar)
V17= FreeParameter("Tool tip",1)
Insert_profile= ToolInsertProfile(Tool_ent,V17)
Stat= AutoNameGroup(Insert_profile,Group_name$)
Important_pts:!
Pt_group= CreateGroup("")
Pz= PointXYZ(0,0,0)
Stat= AddToGroup(Pt_group,Pz)
Pc= ToolInsertCenter(Tool_ent,V17)
Stat= AddToGroup(Pt_group,Pc)
Stat= AutoNameGroup(Pt_group,Pts_name$)
Shank_len_wth:!
Shank_path= ShankToolBar(Tool_ent,V17,WsFalse,WsBoringBar)
Stat= AutoNameGroup(Shank_path,Shank_name$)

RecordFunctionOff
CloseVarRecord
ResizeAll
IF NOT ValidGeometry(Holder_ent) THEN
        DelLastVarRecord
	GOTO Start
END IF



Pick_entity:!

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

