
! script name: vstrategy.d/opstrategy
! topic: read feature strategy

!A
!A NAME:
!A
!A 	READ FEATURE STRATEGY (TOOLS)
!A
!A DESCRIPTION:
!A
!A	Feature strategies are small loadable variational programs.
!A	Synergy uses feature strategies for Hole Features.
!A	Hole features are multiple tool operations centered about a point.
!A	For example, a tapping hole feature could consist of 3 tools:
!A	A Spot drill, the tap size drill, and the tap itself. At each
!A	location the hole feature is placed, a hole is created for every
!A	tool in the operation. So for a tap operation 3 holes of different
!A	diameters and depths are created and associated with the appropriate
!A	tool. 
!A	
!A~ image location - images/holefeature_tap.jpg
!A~ image location - images/holefeature_lp.jpg
!A	
!A	Each hole feature has variables and parameters associated with it.
!A	These variables can be edited under the buttons
!A	D->Mill->Modify->Feature Variables and 
!A	D->Mill->Modify->Feature Parameters.
!A	
!A	The default values for the Hole Features are contained in Information
!A	Packets. The information packets associated with existing Hole Features
!A	can be viewed and modified using the menus located under
!A	D->Drft Ctrl->Packets.
!A
!A	The Hole Feature Packets are located in the following folder:
!A	C:/usr/weber/database/properties/HoleFeatures.d/Inches.d or Metric.d.
!A	These are ASCII files and can be created or modified in Synergy
!A	or using your favorite plain text editor WordPad, vi etc.
!A
!A	The Hole Feature strategies are located in 
!A		C:/usr/weber/database/strategies/holefeatures/inches or metric.
!A	The strategies are also ASCII files.
!A	Each hole feature type needs a strategy which reads its default
!A	data from an information packet.
!A
!A	The user may modify or create new strategies or they may
!A	contract Weber Systems to develop the strategies for them.
!A
!B INSTRUCTIONS:
!B
!B	This script is used for reading feature strategies with tools.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: read feature strategy tools ")
DIM Destination$[256],Answer$[256]
DIM Name$[256],File_name$[256],Tool_name$[256],Strategy$[256]
DIM Strategy_name$[256]
DIM A$[256],B$[256]
DIM Toolid$[256],Timage$[256]
DIM Toolmat$[256],Search1$[256],Search2$[256]
DIM Dir$[256]
DIM D_label$[256],Sub_label$[256],F_label$[256]
DIM Choice$[256],Mask$[32]
DIM Tool_class$[256]
DIM Namelist$[32000],Namelist2$[32000],Varlist$[32000]
DIM Data$[32000]
DIM Iormm$[64],Sformm$[64]
DIM Tmp_a$[256]
DIM Sub_dir$[256],Bc$[32],Ec$[32]

DeActivateUndo
Lf$= CHR$(10)

IF ARGC<2 THEN
	Bc$=""
	Sub_dir$=""
	Ec$=""
ELSE
	Bc$=":"
	Sub_dir$=ARGV(1)
	Ec$="/"
END IF

IF ARGC<3 THEN
	Strategy_name$=""
ELSE
	A$=ARGV(2)
	Strategy_name$= TRIM$(A$)
END IF

Read_from_file:!
Stat= NamedVarStr("strategy directory",WsStrategyVars,"/usr/weber/database/strategies",Dir$)
IF CurrentUnits= WsMetric THEN 
	Dir$= FileNameString(Dir$,"holefeatures/metric/",Sub_dir$)
ELSE
	Dir$= FileNameString(Dir$,"holefeatures/inches/",Sub_dir$)
END IF
IF LEN(Strategy_name$) THEN 
	Strategy$= FileNameString(Dir$,Strategy_name$)

	F_type= DoesFileExist(Strategy$)
        SELECT F_type
	CASE 1
		GOTO Tool_refs
        CASE 2
		Dir$= Strategy$
		Strategy$=""
        END SELECT
END IF


Ask_strategy_file:!
D_label$="DIRECTORY"
Sub_label$="SUB DIRECTORIES"
F_label$="STRATEGY FILES"
Choice$="STRATEGY FILE"

Stat=UserFileBox(Dir$,Mask$,D_label$,Sub_label$,F_label$,Choice$)
Stat=SetInputFormat("a99","")
Stat=GetValue("SELECT STRATEGY FILE",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$= "CANCEL" THEN
	Destination$= "typecontrol"
	GOTO Leave
END IF
LowerFileBox
Strategy$= Answer$
IF NamedVarVal("save dirs",WsSystemVars,0) THEN V1=CreateVariable("strategy directory",WsStrategyVars,PathNameDirectory(Answer$))

Tool_refs:!
A$="START TOOL REFERENCES:"
B$="END TOOL REFERENCES:"
Stat= ReadFileSegment(Strategy$,A$,B$,Data$)
Num_references= StringFieldCount(Data$,Lf$)
IF Num_references THEN
	GOSUB Get_material
	FOR I= 1 TO Num_references
		Stat= StringFieldStr(Data$,Lf$,I,A$)

		Stat= StringFieldStr(A$,":",1,Tool_name$)
		IF Stat THEN Next_i
		Stat= StringFieldStr(A$,":",2,File_name$)
		IF Stat THEN Next_i

		Tool=FindUserData(Tool_name$,WsToolData)
		IF NOT ValidGeometry(Tool) THEN
			GOSUB Get_tool
		END IF
Next_i: NEXT I
END IF 
V1=CreateVariable("current strategy",WsStrategyVars,Strategy$)
GOTO Leave

Get_material:!
Material=FindUserData("MATERIAL",WsMaterial)
IF NOT ValidGeometry(Material) THEN
	Stat= NamedVarStr("material dir",WsSystemVars,"/usr/weber/util/tooldata/materials/",Dir$)
        D_label$="MATERIALS DIRECTORY"
        Choice$="MATERIALS SELECTED"
        Stat=DirectoryNames(Dir$,"*",Namelist$)
	Stat= AlphabeticalOrder(Namelist$,",",WsAscending,Namelist2$)
        Stat=GeneralListBox(D_label$,Choice$,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
RETURN

Get_tool:!
Tool=ReadUserData(WsToolData,Tool_name$,File_name$)
IF NOT ValidGeometry(Tool) THEN Leave_get_tool
Stat=PutUserString(Tool,"Tool file name:",File_name$)

Stat=GetUserString(Tool,"Tool type:",Toolid$)
Stat=GetUserString(Tool,"Tool image:",Timage$)
Stat=GetUserString(Tool,"Tool material:",Toolmat$)

Tool_dia=GetUserValue(Tool,"Diameter:")
Tool_length=GetUserValue(Tool,"Gage length:")
F1=GetUserValue(Tool,"Machinability factor:")

IF Units= WsMetric THEN
	Ft_or_m=1000
ELSE
	Ft_or_m=12
END IF

SELECT Toolid$
CASE "ENDMILL","COUNTERBORE","BALLMILL","TAPERMILL","BULLMILL","CHAMFERMILL","THREADER"
	IF Units= WsMetric THEN
		Iormm$="(mmpt)("&Toolmat$&"):"
		Sformm$="(smpm)("&Toolmat$&"):"
	ELSE
		Iormm$="(ipt)("&Toolmat$&"):"
		Sformm$="(sfpm)("&Toolmat$&"):"
	END IF
	SELECT Toolid$
	CASE "COUNTERBORE"
		Search1$="Counterbore/spotface"&Sformm$
		Search2$="Counterbore/spotface"&Iormm$
	CASE "THREADER"
		Search1$="Thread Milling"&Sformm$
		Search2$="Thread Milling"&Iormm$
	CASE ELSE
		Corner_radius=GetUserValue(Tool,"Corner radius:")
		Max_depth_cut=GetUserValue(Tool,"Maximum depth of cut:")
		Search1$="Finish "&Sformm$
		Search2$="Rough "&Iormm$
	END SELECT
	Nflutes=GetUserValue(Tool,"Number flutes:")
	Tdm=GetUserValue(Tool,"Manufacturability:")
	IF Tdm<=.001 THEN Tdm=1.0
	Ipt=GetUserValue(Material,Search2$)
	Factor= Tdm*Ipt*Nflutes
	Surface_speed=GetUserValue(Material,Search1$)

CASE "DRILL","TWIST DRILL","CENTER DRILL","COUNTER SINK","REAMER","BORING BAR","PORT CUTTER"

	IF Units= WsMetric THEN
		Sformm$="(smpm)("&Toolmat$&"):"
	ELSE
		Sformm$="(sfpm)("&Toolmat$&"):"
	END IF

	SELECT Toolid$
	CASE "REAMER"
		Search1$="Reaming"&Sformm$
		Tdm=GetUserValue(Material,"ReamManufacturability:")
	CASE "BORING BAR"
		Search1$="Boring"&Sformm$
		Tdm=GetUserValue(Material,"BoreManufacturability:")
	CASE ELSE
		Drill_angle=GetUserValue(Tool,"Point angle:")
		Search1$="Twist Drill"&Sformm$
		Tdm=GetUserValue(Material,"TdrillManufacturability:")
	END SELECT

	Ipr=GetFeedrate(Tool,Material,2)
	IF Tdm<=.001 THEN Tdm=1.0
	Factor= Tdm*Ipr
	Surface_speed=GetUserValue(Material,Search1$)

CASE "TAP"
	Surface_speed= GetTapSfpm(Tool,Material)
	IF Units= WsMetric THEN
		Ipr= GetUserValue(Tool,"Pitch:")
	ELSE
		Tpi=GetUserValue(Tool,"Threads-inch:")
		Ipr= 1/Tpi
	END IF
	Factor= Ipr
END SELECT

Speed=F1*(Ft_or_m*Surface_speed)/(PI*Tool_dia)
Feed=Factor*Speed

Speed=PROUND(Speed,0)
Feed=PROUND(Feed,-2*(Units=WsInch))

IF NOT GetFeedrate(Tool,Material) THEN
	IF Units=WsMetric THEN
		Stat=PutUserValue(Tool,"Feed(mmpm):",Feed)
	ELSE
		Stat=PutUserValue(Tool,"Feed(ipm):",Feed)
	END IF
END IF
IF NOT GetSpeed(Tool,Material) THEN Stat=PutUserValue(Tool,"Speed(rpm):",Speed)

Leave_get_tool:!
RETURN

Leave:!
LowerFileBox
LowerSelectBox
IF NOT LEN(Destination$) THEN
	LOAD "vstrategy.d/readoperation"&Bc$&Sub_dir$
ELSE
        LOAD Destination$
END IF
END


