COMPILE FUNCTION Comm_Surface_Scan(Instruction, Parm1,Parm2)

/*
	Commuter module for Surface_Scan window
	
	04/22/2006 - John C. Henry, J.C. Henry & Co., Inc.
*/

DECLARE SUBROUTINE Set_Property, End_Dialog, Send_Event, Set_Status, Center_Window, Post_Event, obj_WO_Mat_Log
DECLARE SUBROUTINE ErrMsg, Send_Message, Set_Property, Send_Event, Btree.Extract, obj_AppWindow, obj_WO_Mat
DECLARE FUNCTION Get_Property, Get_Status, Dialog_Box, Utility, Center_Window, Popup, Collect.Ixvals
DECLARE FUNCTION Send_Message

$INSERT POPUP_EQUATES
$INSERT APPCOLORS
$INSERT WO_STEP_EQUATES
$INSERT PROD_SPEC_EQU
$INSERT LSL_USERS_EQU
$INSERT SURFACE_SCAN_EQUATES
$INSERT TOOL_EQUATES
$INSERT TOOL_CLASS_EQUATES

EQU CRLF$	TO \0D0A\

ErrTitle = 'Error in Comm_Surface_Scan'
ErrorMsg = ''

Result = ''

BEGIN CASE
	CASE Instruction = 'Create' 		; GOSUB Create
	CASE Instruction = 'Refresh'		; GOSUB Refresh
	CASE Instruction = 'Read'			; GOSUB Read
	CASE Instruction = 'Write'			; GOSUB Write
	CASE Instruction = 'Clear'			; GOSUB Clear
	CASE Instruction = 'LUStage'		; GOSUB LUStage
	CASE Instruction = 'LURdsNo'		; GOSUB LURdsNo
	CASE Instruction = 'LUTool'			; GOSUB LUTool
	CASE Instruction = 'SumOfDefAvgLF'	; GOSUB SumOfDefAvgLF
	CASE Instruction = 'HazeAvgAvgLF'	; GOSUB HazeAvgAvgLF
	CASE Instruction = 'Close'			; GOSUB Close
	CASE Instruction = 'Sign'			; GOSUB Sign
	CASE 1
		ErrorMsg = 'Unknown Instruction passed to routine.'
		ErrMsg(ErrorMsg)
END CASE

RETURN Result



* * * * * * *
Create:
* * * * * * *

obj_Appwindow('Create',@WINDOW)

GOSUB Refresh


RETURN

* * * * * * *
Clear:
* * * * * * *


* * * * * * *
Refresh:
* * * * * * *

Ctrls  = @WINDOW:'.SUM_OF_DEFECTS_SPEC':@RM			; Props  = 'TEXT':@RM
Ctrls := @WINDOW:'.HAZE_AVG_SPEC':@RM				; Props := 'TEXT':@RM
Ctrls := @WINDOW:'.SUM_OF_DEF_MIN':@RM				; Props := 'TEXT':@RM
Ctrls := @WINDOW:'.SUM_OF_DEF_MAX':@RM				; Props := 'TEXT':@RM
Ctrls := @WINDOW:'.SUM_OF_DEF_AVG':@RM				; Props := 'TEXT':@RM
Ctrls := @WINDOW:'.HAZE_AVG_AVG':@RM				; Props := 'TEXT':@RM
Ctrls := @WINDOW:'.SCAN_TOOL'						; Props := 'TEXT'

Vals = Get_Property(Ctrls,Props)

SumOfDefectsSpec	= ICONV(Vals[1,@RM],'MD0')
HazeAvgSpec			= Vals[COL2()+1,@RM]
SumOfDefectsMin		= ICONV(Vals[COL2()+1,@RM],'MD0')
SumOfDefectsMax		= ICONV(Vals[COL2()+1,@RM],'MD0')
SumOfDefectsAvg		= Vals[COL2()+1,@RM]
HazeAvgAvg			= Vals[COL2()+1,@RM]
ScanTool			= Vals[COL2()+1,@RM]


OutOfSpec = ''
IF SumOfDefectsSpec NE '' THEN

	IF SumOfDefectsMin GE SumOfDefectsSpec THEN
		OutOfSpec = 1
		Set_Property(@WINDOW:'.SUM_OF_DEF_MIN','BACKCOLOR',RED$)
	END

	IF SumOfDefectsMax GE SumOfDefectsSpec THEN
		OutOfSpec = 1
		Set_Property(@WINDOW:'.SUM_OF_DEF_MAX','BACKCOLOR',RED$)
	END
	
	IF SumOfDefectsAvg GE SumOfDefectsSpec THEN
		OutOfSpec = 1
		Set_Property(@WINDOW:'.SUM_OF_DEF_AVG','BACKCOLOR',RED$)
	END
END

IF HazeAvgSpec NE '' THEN
	IF HazeAvgAvg GE HazeAvgSpec THEN
		OutOfSpec = 1
		Set_Property(@WINDOW:'.HAZE_AVG_SPEC','BACKCOLOR',RED$)
	END
END

IF OutOfSpec THEN
	Set_Property(@WINDOW:'.OUT_OF_SPEC','VISIBLE',1)
END ELSE
	Set_Property(@WINDOW:'.OUT_OF_SPEC','VISIBLE',0)
	Set_Property(@WINDOW:'.SUM_OF_DEF_MAX','BACKCOLOR',WHITE$)
	Set_Property(@WINDOW:'.SUM_OF_DEF_AVG','BACKCOLOR',WHITE$)
	Set_Property(@WINDOW:'.HAZE_AVG_AVG','BACKCOLOR',WHITE$)
END

ReadyToSign = 1

IF ScanTool = '' THEN ReadyToSign = 0

IF ScanTool = 'Waived' THEN
	NULL
END ELSE
	IF SumOfDefectsSpec NE '' THEN
		IF SumOfDefectsMin = '' THEN ReadyToSign = 0
		IF SumOfDefectsMax = '' THEN ReadyToSign = 0
		IF SumOfDefectsAvg = '' THEN ReadyToSign = 0
	END

	IF HazeAvgSpec NE '' THEN
		IF HazeAvgAvg = '' THEN ReadyToSign = 0
	END
END

IF ReadyToSign THEN
	Set_Property(@WINDOW:'.SIGN_BUTTON','ENABLED',1)
END ELSE
	Set_Property(@WINDOW:'.SIGN_BUTTON','ENABLED',0)
END

IF Get_Property(@WINDOW:'.SCAN_USER','TEXT') = '' THEN
	Set_Property(@WINDOW:'.SCAN_DTM','BACKCOLOR',WHITE$)
	Set_Property(@WINDOW:'.SCAN_USER','BACKCOLOR',WHITE$)
END ELSE
	Set_Property(@WINDOW:'.SCAN_DTM','BACKCOLOR',GREEN$)
	Set_Property(@WINDOW:'.SCAN_USER','BACKCOLOR',GREEN$)
END


RETURN


* * * * * * *
Read:
* * * * * * *

Stage = Get_Property(@WINDOW:'.STAGE','TEXT')


IF Stage = 'FW' THEN
	IF Get_Property(@WINDOW:'.SUM_OF_DEF_MIN','TEXT') = '' THEN
		Set_Property(@WINDOW:'.SUM_OF_DEF_MIN','TEXT','0')
	END
	IF Get_Property(@WINDOW:'.SUM_OF_DEF_MAX','TEXT') = '' THEN
		Set_Property(@WINDOW:'.SUM_OF_DEF_MAX','TEXT','0')
	END
	*Set_Property(@WINDOW:'.SUM_OF_DEF_AVG','FOCUS',1)
END ELSE
	*Set_Property(@WINDOW:'.SUM_OF_DEF_MIN','FOCUS',1)
END


IF Get_Property(@WINDOW:'.RECIPE','DEFPROP') = '' THEN
	CurrID = Get_Property(@WINDOW,'ID')
	WMIKey = FIELD(CurrID,'*',1,3)
	Recipe = XLATE('WM_IN',WMIKey,'SPEC_PRE_SURFSCAN_RECIPE','X')
	Set_Property(@WINDOW:'.RECIPE','DEFPROP',Recipe)
END

GOSUB Refresh

RETURN


* * * * * * *
Write:
* * * * * * *

Signature = Get_Property(@WINDOW:'.SCAN_USER','TEXT',ScanUser)

IF Signature = '' THEN
	ErrMsg('Signature Required')
	Result = 0
END ELSE
	Result = 1
END

RETURN


* * * * * * *
Sign:
* * * * * * *

Valid = Dialog_Box('NDW_VERIFY_USER', @Window, @User4)
Valid = Valid<1>

IF Valid THEN
			
	WONo	= Get_Property(@WINDOW:'.WO_NO','DEFPROP')
	WOStep	= Get_Property(@WINDOW:'.WO_STEP','DEFPROP')
	CassNo	= Get_Property(@WINDOW:'.CASS_NO','DEFPROP')
	Stage	= Get_Property(@WINDOW:'.STAGE','DEFPROP')
	
	PSNo = XLATE('WO_STEP',WONo:'*':WOStep,WO_STEP_PROD_SPEC_ID$,'X')
	ReactorType = XLATE('PROD_SPEC',PSNo,PROD_SPEC_REACTOR_TYPE$,'X')
	
	ScanDTM = OCONV(Date(),'D4-'):' ':OCONV(Time(),'MTS')
	ScanUser = @USER4
	
	ScanTool = Get_Property(@WINDOW:'.SCAN_TOOL','DEFPROP')
			
	ToolRec = XLATE('TOOL',ScanTool,'','X')
					
	ToolWH	= ToolRec<TOOL_TOOL_WH$>
	ToolLoc	= ToolRec<TOOL_TOOL_LOC$>
	
	IF ReactorType = 'EPP' OR ReactorType = 'P' THEN
		Parent = Get_Property(@WINDOW,'PARENT')
		
		IF Parent = 'WM_OUT' THEN
			StatusStage = 'MO_PSTS'
			owmParms = WONo:@RM:CassNo:@RM:WOStep:@RM:StatusStage:@RM:ScanUser:@RM:ScanDTM	
			*obj_WO_Mat('SetSignature',owmParms)
				
			IF Get_Status(errCode) THEN
				ErrMsg(errCode)
				RETURN
			END ELSE
				Set_Property(@WINDOW:'.SCAN_DTM','TEXT',ScanDTM)
				Set_Property(@WINDOW:'.SCAN_USER','TEXT',ScanUser)
			END
			
			LogFile	= 'WO_MAT'			; WOMLParms  = LogFile:@RM
			LogDTM	= ScanDTM			; WOMLParms := LogDTM:@RM
			Action	= WOStep:'MO_PSTS'	; WOMLParms := Action:@RM
			WhCd	= ToolWH			; WOMLParms := WhCd:@RM
			LocCd	= ToolLoc			; WOMLParms := LocCd:@RM
			WONos	= WONo				; WOMLParms := WONos:@RM
			CassNos	= CassNo			; WOMLParms := CassNos:@RM
			UserID	= @USER4			; WOMLParms := UserID:@RM
			Tags	= ''				; WOMLParms := Tags:@RM
			ToolID	= ScanTool			; WOMLParms := ToolID

			*obj_WO_Mat_Log('Create',WOMLParms)			;* Add WOStep:'MO_PSTS' to WO_MAT Event Log
			
		END
		
	END ELSE

		BEGIN CASE
			CASE Stage = 'PE'	; StatusStage = 'PRES'
			CASE Stage = 'FW'	; StatusStage = 'WFRS'
			CASE Stage = 'PC'	; StatusStage = 'PSTS'
		END CASE
		
		owmParms = WONo:@RM:CassNo:@RM:WOStep:@RM:StatusStage:@RM:ScanUser:@RM:ScanDTM	
*		obj_WO_Mat('SetSignature',owmParms)
			
		IF Get_Status(errCode) THEN
			ErrMsg(errCode)
			RETURN
		END ELSE
			Set_Property(@WINDOW:'.SCAN_DTM','TEXT',ScanDTM)
			Set_Property(@WINDOW:'.SCAN_USER','TEXT',ScanUser)
		END
		
		LogFile	= 'WO_MAT'				; WOMLParms  = LogFile:@RM
		LogDTM	= ScanDTM				; WOMLParms := LogDTM:@RM
		Action	= WOStep:StatusStage	; WOMLParms := Action:@RM
		WhCd	= ToolWH				; WOMLParms := WhCd:@RM
		LocCd	= ToolLoc				; WOMLParms := LocCd:@RM
		WONos	= WONo					; WOMLParms := WONos:@RM
		CassNos	= CassNo				; WOMLParms := CassNos:@RM
		UserID	= @USER4				; WOMLParms := UserID:@RM
		Tags	= ''					; WOMLParms := Tags:@RM
		ToolID	= ScanTool				; WOMLParms := ToolID

		obj_WO_Mat_Log('Create',WOMLParms)			;* Add WOStep:'xxxS' to WO_MAT Event Log
		
		
		
	END	;* End of check for reactor type
		
		
	
	
END ELSE
	ErrMsg('Invalid password entry.')
	RETURN
END


Send_Event(@WINDOW,'WRITE')
	
Post_Event(@WINDOW,'CLOSE')

RETURN


* * * * * * *
SumOfDefAvgLF:
* * * * * * *

GOSUB Refresh

RETURN


* * * * * * *
HazeAvgAvgLF:
* * * * * * *

GOSUB Refresh

RETURN


* * * * * * *
LUStage:
* * * * * * *

FocusControl = Parm1

IF FocusControl = '' THEN
	FocusControl = Get_Property(@WINDOW,'FOCUS')
END

Stage = Popup(@WINDOW,'','STAGE')

IF Stage = '' THEN RETURN

obj_AppWindow('LUValReturn',Stage:@RM:FocusControl)

RETURN


* * * * * * 
LURdsNo:
* * * * * * 

FocusControl = Parm1

IF FocusControl = '' THEN
	FocusControl = Get_Property(@WINDOW,'FOCUS')
END

WONo    = Get_Property(@Window:'.WO_NO', 'TEXT')
RDSKeys = Dialog_Box('NDW_RDS_QUERY', @Window, WONo : @FM : 'quick')

IF RDSKeys = '' THEN RETURN

CONVERT @FM TO @VM IN RDSKeys

TypeOver            = ''
TypeOver<PDISPLAY$> = RDSKeys
TypeOver<PMODE$>    = 'K'
TypeOver<PTYPE$>    = 'F'
TypeOver<PFIELD$>   = '3'
TypeOver<PSELECT$>  = 1

RDSKey = Popup(@WINDOW,TypeOver,'RDS_QUERY')

IF RDSKey = '' THEN RETURN

obj_AppWindow('LUValReturn',RDSKey:@RM:FocusControl)


RETURN



* * * * * * *
LUTool:
* * * * * * *

ToolKeys		= XLATE('TOOL_CLASS','TENCOR',TOOL_CLASS_TOOL$,'X')

TypeOver = ''
TypeOver<PMODE$> = 'K'
TypeOver<PDISPLAY$> = ToolKeys

ToolID = Popup(@WINDOW,TypeOver,'TOOLS')

IF ToolID = '' THEN RETURN

obj_Appwindow('LUValReturn',ToolID:@RM:@WINDOW:'.SCAN_TOOL')

RETURN

* * * * * * *
Close:
* * * * * * *



RETURN

