
! script name: operations.d/cmmholeoper

!A
!A NAME:
!A
!A 	CMM Operation Control
!A
!A DESCRIPTION:
!A
!A	This script will call the necessary scripts to load the operation
!A	information for a hole probe.
!A

stat=ChangeLabelStr("ScriptNameStatus","Function: cmm hole probe operation control")

COM /Ops_var_design/ Use_variational
DIM Description$[256],Destination$[256],Answer$[256],Dir$[256],Dir1$[256]
DIM File_name2$[256],Tldir$[256],Ques$[256],Mask$[256]
DIM Which_tool$[256],Ref_tool$[256],Op_dir$[256]
DIM Namelist$[32000],Op_names$[512]
DIM Namelist2$[32000]
DIM Current_op$[256]

DeActivateUndo
Stat=NamedVarStr("current operation",WsSystemVars,"",Current_op$)
IF Current_op$="" THEN Current_op$="OPERATION DATA"
IF ARGC<2 THEN
	Use_variational= 0
ELSE
	Use_variational= VAL(ARGV(1))
END IF

Stat= NamedVarStr("operations dir",WsSystemVars,"/usr/weber/util/tooldata/operations2_in/",Dir$)
Stat= NamedVarStr("tools dir",WsSystemVars,"/usr/weber/util/tooldata/tools_in/",Dir1$)
Dir$= FileNameString(Dir$,"probing")
IF NOT DoesFileExist(Dir$) THEN Leave

Pick_direct:!

Stat=DirectoryNames(Dir$,"*",Namelist$)
Stat= AlphabeticalOrder(Namelist$,",",WsAscending,Namelist2$)
Stat=GeneralListBox("OPERATIONS","OPERATION SELECTED",Namelist2$)

Stat=SetInputFormat("a99","")
Stat=GetValue("INPUT OPERATION ",Answer$)
IF ExitScript(Destination$) OR Answer$="CANCEL" THEN Leave
LowerSelectBox

Op_group=GrpFindUserData("OPERATION DATA",WsOperation)
IF ValidGeometry(Op_group) THEN Stat= DeleteGroup(Op_group,1)

OperData= ReadUserData(WsOperation,"OPERATION DATA",FileNameString(Dir$,Answer$))
IF NOT ValidGeometry(OperData) THEN Leave

Incr_desc=0
Stat= GetUserString(OperData,"Operations:",Op_names$)
IF CheckUserField(OperData,"Description:",1) THEN
	Stat= GetUserString(OperData,"Description:",Description$)
	IF UPC$(Description$)="FORCE" OR Description$="" THEN
		Stat= GetValue("OPERATION DESCRIPTION",Description$)
		IF ExitScript(Destination$) THEN Leave
		Stat= PutUserString(OperData,"Description:",Description$)
	ELSE
		Incr_desc=1
	END IF
ELSE
	Stat= GetValue("OPERATION DESCRIPTION",Description$)
	IF ExitScript(Destination$) THEN Leave
	Stat= PutUserString(OperData,"Description:",Description$)
END IF

Start_loop:J=1
LOOP
Stat= StringFieldStr(Op_names$,",",J,Which_tool$)
EXIT IF Which_tool$=""
Stat= PutUserString(OperData,"Tool "&VAL$(J)&":",Which_tool$)

IF CheckUserField(OperData,Which_tool$&" reference:",1) THEN
	Stat= GetUserString(OperData,Which_tool$&" reference:",B$)
	Stat= GetUserString(OperData,B$&" tool file:",Ref_tool$)
	Stat= PutUserString(OperData,Which_tool$&" tool file:",Ref_tool$)
ELSE
	IF CheckUserField(OperData,Which_tool$&" directory:",1) THEN
		Stat= GetUserString(OperData,Which_tool$&" directory:",Tldir$)
		Mask$="*"
		IF CheckUserField(OperData,Which_tool$&" mask:",1) THEN
			Stat= GetUserString(OperData,Which_tool$&" mask:",Mask$)
		END IF
		Stat= DirectoryNames(FileNameString(Dir1$,Tldir$),Mask$,Namelist$)
		Stat= AlphabeticalOrder(Namelist$,",",WsAscending,Namelist2$)
		Stat=GeneralListBox("TOOL AVAILABLE","TOOL SELECTED",Namelist2$)

		IF CheckUserField(OperData,Which_tool$&" question:",1) THEN
			Stat= GetUserString(OperData,Which_tool$&" question:",Ques$)
			Stat=GetValue(Ques$,Answer$)
		ELSE
			Stat=GetValue("INPUT TOOL FROM "&Tldir$,Answer$)
		END IF
		IF ExitScript(Destination$) OR Answer$="CANCEL" THEN Leave
		Stat= PutUserString(OperData,Which_tool$&" tool file:",FileNameString(Tldir$,Answer$))
	END IF
END IF
J= J+1
END LOOP

Current_op$=Description$
IF Incr_desc THEN
	Op_count=1
	LOOP
		Current_op$=Description$&"--#"&VAL$(Op_count)
		AssocData= FindUserData(Current_op$,WsOperation)
		EXIT IF NOT ValidGeometry(AssocData)
		Op_count= Op_count+1
	END LOOP
END IF
Stat=ChangeDataName(OperData,Current_op$)
V1=CreateVariable("current operation",WsSystemVars,Current_op$)

LowerSelectBox
Stat=SetInputFormat("n4","")

Stat= PutUserValue(OperData,"Number tools:",J-1)
ToolGrp= FindNamedGrp("OPER TOOLS")
IF ValidGeometry(ToolGrp) THEN Stat= DeleteEntity(ToolGrp)
ToolGrp= CreateGroup("OPER TOOLS")
Stat= GetUserString(OperData,"Operation script:",Answer$)
print "Answer$ = ",Answer$
LOAD Answer$

Leave:!
LowerSelectBox
Stat=SetInputFormat("n4","")
IF ValidGeometry(ToolGrp) THEN Stat= DeleteEntity(ToolGrp)

IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END

