COMPILE FUNCTION Comm_PRS_Stage(EntID,Event,Parm1,Parm2,Parm3,Parm4,Parm5)

/*
	Commuter module for PRS_Layer (Product Specification Layer) window

	10/22/2012  - John C. Henry, J.C. Henry & Co., Inc.
*/

DECLARE SUBROUTINE Set_Property,  Set_Status, ErrMsg, Set_Property, obj_AppWindow, Send_Event, Security_Err_Msg
DECLARE SUBROUTINE Send_Message, Btree.Extract, Comm_Prod_Spec, Forward_Event, Post_Event
DECLARE FUNCTION Get_Property, Get_Status, Popup, Send_Message, Msg, Start_Window, MemberOf, Security_Check
DECLARE FUNCTION Comm_Prod_Spec


$INSERT POPUP_EQUATES
$INSERT MSG_EQUATES
$INSERT APPCOLORS
$INSERT PRS_STAGE_EQUATES
$INSERT PRS_PROP_EQUATES
$INSERT TOOL_CLASS_EQUATES
$INSERT SECURITY_RIGHTS_EQU
$INSERT STYLE_EQUATES
$INSERT LOGICAL
$INSERT PROD_SPEC_EQUATES

EQU CRLF$	TO \0D0A\


EQU EDITABLE$			TO 4
EQU PROTECTED$			TO 8			;* Protected  - Edittable COLSTYLE constants
EQU MULTILINE_STYLE$	TO 512 			;* MultiLine Select
EQU LOCKED$				TO 8192
EQU DROPDOWN_STYLE$		TO 131072

EQU HIDDEN$				TO 32
EQU SKIPPED$			TO 4100

EQU COL$CLEAN_TOOL		TO 1
EQU COL$CLEAN_TOOL_DESC	TO 2

EQU COL$SURFSCAN_RECIPE		TO 1
EQU COL$SURFSCAN_DEFECTS	TO 2
EQU COL$SURFSCAN_HAZE		TO 3
EQU COL$SURFSCAN_SAMP_SIZE	TO 4

EQU COL$LPD				TO 1
EQU COL$SCRATCHES		TO 2
EQU COL$SCRATCH_LEN		TO 3
EQU COL$PITS			TO 4
EQU COL$MOUNDS			TO 5
EQU COL$STACK_FAULTS	TO 6
EQU COL$SPIKES			TO 7
EQU COL$SPOTS			TO 8
EQU COL$FOV				TO 9
EQU COL$BL_DEFECTS		TO 10


EQU COL$MET_TEST			TO 1
EQU COL$MET_PROP			TO 2
EQU COL$MET_PROP_DESC		TO 3
EQU COL$MET_TOOL_CLASS		TO 4
EQU COL$MET_RECIPE			TO 5
EQU COL$MET_RECIPE_PATTERN	TO 6
EQU COL$MET_MIN				TO 7
EQU COL$MET_MAX				TO 8
EQU COL$MET_PHASE_MIN       TO 9
EQU COL$MET_SLOT			TO 10
EQU COL$MET_WFR_QTY			TO 11
EQU COL$MET_R_SCHED			TO 12
EQU COL$MET_INTERVAL		TO 13
EQU COL$MET_START			TO 14
EQU COL$MET_SEQUENCE		TO 15


ErrTitle = 'Error in Comm_PRS_Stage'
ErrorMsg = ''

Result = ''

BEGIN CASE
	CASE EntID = @WINDOW
		BEGIN CASE
			CASE Event = 'CLEAR'			; GOSUB Clear
			CASE Event = 'CREATE' 			; GOSUB Create
			CASE Event = 'CLOSE'			; GOSUB Close
			CASE Event = 'DELETE'			; GOSUB Delete
			CASE Event = 'READ'				; GOSUB Read
			CASE Event = 'WRITE'			; GOSUB Write
			CASE Event[1,3] = 'QBF'			; GOSUB Refresh
		END CASE
	
	
	CASE EntID = @WINDOW:'.LU_STAGE' AND			Event = 'CLICK'		; GOSUB LUStage
	CASE EntID = @WINDOW:'.LU_CLEAN_TOOL' AND 		Event = 'CLICK'		; GOSUB LUCleanTool
	CASE EntID = @WINDOW:'.LU_CLEAN_RECIPE' AND		Event = 'CLICK'		; GOSUB LUCleanRecipe
	CASE EntID = @WINDOW:'.LU_SURFSCAN_RECIPE' AND	Event = 'CLICK'		; GOSUB LUSurfScanRecipe
	CASE EntID = @WINDOW:'.VIRGIN_DEFAULTS' AND		Event = 'CLICK'		; GOSUB SurfscanDefaults
	CASE EntID = @WINDOW:'.BL_DEFAULTS' AND			Event = 'CLICK'		; GOSUB SurfscanDefaults
	CASE EntID = @WINDOW:'.STAGE' AND				Event = 'CHANGED'	; GOSUB Refresh
	CASE EntID = @WINDOW:'.TABCONTROL' AND 			Event = 'CLICK'		; GOSUB TabClick
	CASE EntID = @WINDOW:'.LU_TOOL_CLASS' AND		Event = 'CLICK'		; GOSUB LUToolClass
	CASE EntID = @WINDOW:'.LU_ACTION' AND			Event = 'CLICK'		; GOSUB LUAction
	
	CASE EntID = @WINDOW:'.CLEAN_TOOL'
		BEGIN CASE
			CASE Event = 'CHANGED'			; GOSUB Refresh
		
		END CASE
		
	CASE EntID = @WINDOW:'.MET_TEST'
		BEGIN CASE
			CASE Event = 'LOSTFOCUS' 		; GOSUB MetTestLF
			CASE Event = 'POSCHANGED'		; GOSUB MetTestPC
		END CASE
		
		
	CASE 1
		ErrorMsg = 'Unknown Parameters ':EntID:' - ':Event:' passed to commuter'
		ErrMsg(ErrorMsg)
		
END CASE

IF ErrorMsg NE '' THEN
	ErrMsg(ErrTitle:@SVM:ErrorMsg)
END

RETURN Result


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

obj_Appwindow('Create',@WINDOW)

**** Set Dropdown columns in .MET_TEST edit table ****

MetStyles = Send_Message(@WINDOW:'.MET_TEST','COLSTYLE',0,'')	

MetStyles<COL$MET_TEST>				= BitOr(MetStyles<COL$MET_TEST>,DROPDOWN_STYLE$)
MetStyles<COL$MET_PROP>				= BitOr(MetStyles<COL$MET_PROP>,DROPDOWN_STYLE$)
MetStyles<COL$MET_TOOL_CLASS>		= BitOr(MetStyles<COL$MET_TOOL_CLASS>,DROPDOWN_STYLE$)
MetStyles<COL$MET_RECIPE>			= BitOr(MetStyles<COL$MET_RECIPE>,DROPDOWN_STYLE$)
MetStyles<COL$MET_RECIPE_PATTERN>	= BitOr(MetStyles<COL$MET_RECIPE_PATTERN>,DROPDOWN_STYLE$)
MetStyles<COL$MET_SLOT>				= BitOr(MetStyles<COL$MET_SLOT>,DROPDOWN_STYLE$)
MetStyles<COL$MET_R_SCHED>			= BitOr(MetStyles<COL$MET_R_SCHED>,DROPDOWN_STYLE$)


Send_Message(@WINDOW:'.MET_TEST','COLSTYLE',0,MetStyles)


**** Set Dropdown columsn in SURFSCAN_RECIPE edit table ****

ScanStyles  = Send_Message(@WINDOW : '.SURFSCAN_RECIPE', 'COLSTYLE', 0, '')
ScanStyles<COL$SURFSCAN_RECIPE>     = BitOr(ScanStyles<COL$SURFSCAN_RECIPE>,DTCS_DROPDOWN$)
Send_Message(@WINDOW : '.SURFSCAN_RECIPE', 'COLSTYLE', 0, ScanStyles)
ScanRecipes = XLATE('TOOL_CLASS', 'TENCOR', TOOL_CLASS_RECIPES$, 'X')
Send_Message(@WINDOW : '.SURFSCAN_RECIPE', 'COLFORMAT', COL$SURFSCAN_RECIPE, ScanRecipes)

**** Met Test dropdown contents  *****

PopContents = XLATE('SYSREPOSPOPUPS','LSL2**QA_MET_TEST',8,'X')

ItemCnt = COUNT(PopContents<1>,@VM) + (PopContents<1> NE '')

TestCodes = ''
FOR I = 1 TO ItemCnt
	TestCodes<1,I> = PopContents<1,I,1>
NEXT I

Send_Message(@WINDOW:'.MET_TEST','COLFORMAT',COL$MET_TEST,TestCodes)


* *  Met Property dropdown Contents   * *

PopContents = XLATE('SYSREPOSPOPUPS','LSL2**MET_PROPERTY',8,'X')

ItemCnt = COUNT(PopContents<1>,@VM) + (PopContents<1> NE '')

PropCodes = ''
FOR I = 1 TO ItemCnt
	PropCodes<1,I> = PopContents<1,I,1>
NEXT I

Send_Message(@WINDOW:'.MET_TEST','COLFORMAT',COL$MET_PROP,PropCodes)


* Class Tools is set in the POSCHANGED event for the edit table.

/*

ClassTools = XLATE('TOOL_CLASS',PropCode,'TOOL','X')

Send_Message(@WINDOW:'.MET_TEST','COLFORMAT',COL$MET_TOOL,ClassTools)
*/



* Slots dropdown contents

PopContents = XLATE('SYSREPOSPOPUPS','LSL2**TEST_SLOTS',8,'X')

ItemCnt = COUNT(PopContents<1>,@VM) + (PopContents<1> NE '')

TestSlots = ''
FOR I = 1 TO ItemCnt
	TestSlots<1,I> = PopContents<1,I,1>
NEXT I

Send_Message(@WINDOW:'.MET_TEST','COLFORMAT',COL$MET_SLOT,TestSlots)


* Reactor Schedule dropdown

ReactSchedOpts = @VM:'Yes'

Send_Message(@WINDOW:'.MET_TEST','COLFORMAT',COL$MET_R_SCHED,ReactSchedOpts)

GOSUB Refresh

RETURN


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

GOSUB Refresh

RETURN


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

    Options = ''
    Options<6> = 1 ; // Do not clear form on write
    Set_Property(@Window, 'IOOPTIONS', Options)

    PSNo = Get_Property(@WINDOW : '.PS_NO', 'TEXT')

    PSNStatus = Xlate('PROD_SPEC', PSNo, PROD_SPEC_STATUS$, 'X')

    Savewarn = Get_Property(@Window, 'SAVEWARN')

    Begin Case
        
        Case ( (Savewarn EQ true$) AND (PSNStatus EQ 'A') )
            Result = Comm_Prod_Spec('UpdateRevHist')
            If Result EQ False$ then
                Return False$
            end else
                Forward_Event()
            end
        Case Otherwise$
            Forward_Event()
            
    End Case

RETURN


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

*IF Get_Property(@WINDOW,'@READONLY') THEN
	obj_AppWindow('ReadOnly',@RM:1)			;* Reenables data bound controls
*	Set_Property(@WINDOW,'@READONLY',0)		;* Clear flag on window
*END

GOSUB Refresh

RETURN

* * * * * * *
Close:
* * * * * * *
* If @USER4 EQ 'FRANCOIS_R' then
*    debug    
* end
* PSNo = Get_Property(@WINDOW : '.PS_NO', 'TEXT')
* Stage = Get_Property(@Window : '.STAGE', 'TEXT')
* 
* PRSStageKey = PSNo : '*' : Stage
* If RowExists('PRS_STAGE', PRSStageKey) EQ False$ then
*    // User is adding a new stage to the PSN from the PROD_SPEC form without any details.
*    // Save the new record in case the user has not already done so.
*    Send_Event(@Window, 'WRITE')
* end
obj_Appwindow('DetailReturn')

RETURN


* * * * * * *
Delete:
* * * * * * *

IF Security_Check('Prod Spec Stage',Delete$) THEN
	IF Msg(@WINDOW,'','PRE_DELETE') THEN
	    Result = Comm_Prod_Spec('UpdateRevHist') ; // Returns 1 if user enters revision detail, otherwise returns 0
	END ELSE
		Result = 0		;* Stop event chain user bailed
	END
END ELSE
	Security_Err_Msg('PRS_STAGE',Delete$)
	Result = 0			;* Stop event chain user not worthy
END

RETURN



* * * * * * *
TabClick:
* * * * * * *

IF Parm1 NE '' THEN
	Page = Parm1
END ELSE
	Page = Get_Property(@WINDOW:'.TABCONTROL','VALUE')
END

Set_Property(@WINDOW,'VPOSITION',Page)

RETURN



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

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

IF Stage = 'LWI' OR Stage = 'FWI' OR Stage = 'PRE' THEN
	Set_Property(@WINDOW:'.VIRGIN_DEFAULTS','ENABLED',1)
	Set_Property(@WINDOW:'.BL_DEFAULTS','ENABLED',1)
END ELSE
	Set_Property(@WINDOW:'.VIRGIN_DEFAULTS','ENABLED',0)
	Set_Property(@WINDOW:'.BL_DEFAULTS','ENABLED',0)
END
	
* QBF buttons

Ctrls  = @WINDOW:'.QBF_FIRST_FIX':@RM		; Props  = 'ENABLED':@RM
Ctrls := @WINDOW:'.QBF_PREV_FIX':@RM		; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.QBF_ABS_FIX':@RM			; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.QBF_NEXT_FIX':@RM		; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.QBF_LAST_FIX':@RM		; Props := 'ENABLED':@RM
Ctrls := @WINDOW:'.QBF_STOP_FIX'			; Props := 'ENABLED'

IF Get_Property(@WINDOW,'QBFLIST') = '' THEN
	Vals = 0:@RM:0:@RM:0:@RM:0:@RM:0:@RM:0
END ELSE
	Vals = 1:@RM:1:@RM:1:@RM:1:@RM:1:@RM:1
END

Set_Property(Ctrls,Props,Vals)

* Turn edit table symbolic column backgrounds to green

ETSymbolics = Get_Property(@WINDOW,'@ET_SYMBOLICS')		;* Loaded during 'Create' in obj_Appwindow

ETCtrls	= ETSymbolics<1>
ETCols	= ETSymbolics<2>

FOR I = 1 TO COUNT(ETCtrls,@VM) + (ETCtrls NE '')
	ETCtrl	= ETCtrls<1,I>
	
	ETList = Get_Property(ETCtrl,'LIST')
	FOR Line = 1 TO COUNT(ETList,@FM) + (ETList NE '')
		IF ETList<Line,1> NE '' THEN
			FOR N = 1 TO COUNT(ETCols<1,I>,@SVM) + (ETCols<1,I> NE '')
				stat = Send_Message(ETCtrl,'COLOR_BY_POS',ETCols<1,I,N>,Line,GREEN$)
			NEXT N
		END
	NEXT Line
	
NEXT I



RETURN

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


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

IF ProdStage NE '' AND ProdStage NE CHAR(27) THEN
	obj_Appwindow('LUValReturn',ProdStage:@RM:@WINDOW:'.STAGE')
END
GoSub ResetColors
RETURN
	

* * * * * * *
LUCleanTool:
* * * * * * *

NewTools = Popup(@WINDOW,'','CLEAN_TOOLS')

IF NewTools = '' THEN RETURN

CurrToolArray = Get_Property(@WINDOW:'.CLEAN_TOOL','DEFPROP')

CurrTools = CurrToolArray<1>	;* 1st column is the tool ID's

ctCnt = COUNT(CurrTools,@VM) + (CurrTools NE '')

FOR I = 1 TO ctCnt
	CurrTool = CurrTools<1,I>
	IF CurrTool NE '' THEN
		LOCATE CurrTool IN NewTools USING @VM SETTING Pos THEN
			NewTools = DELETE(NewTools,1,Pos,0)
		END
	END ELSE
		CurrTools<1,I> = NewTools[1,@VM]
		NewTools[1,COL2()] = ''
	END
NEXT I

IF NewTools NE '' THEN
	IF CurrTools = '' THEN
		CurrTools = NewTools
	END ELSE
		CurrTools := @VM:NewTools
	END
END

Set_Property(@WINDOW:'.CLEAN_TOOL','DEFPROP',CurrTools)
Send_Event(@WINDOW:'.CLEAN_TOOL','CALCULATE',COL$CLEAN_TOOL_DESC)

GOSUB Refresh


RETURN




* * * * * * *
LUCleanRecipe:
* * * * * * *

ToolClassCode = 'AKRION' 	;* Only tool class for Surface Scans

Recipes = XLATE('TOOL_CLASS',ToolClassCode,TOOL_CLASS_RECIPES$,'X')

IF Recipes NE '' THEN
	TypeOver = ''
	TypeOver<PDISPLAY$> = Recipes
	
	Recipe = Popup(@WINDOW,Typeover,'CLEAN_RECIPES')
	
	IF Recipe NE '' AND Recipe NE CHAR(27) THEN
		obj_AppWindow('LUValReturn',Recipe:@RM:@WINDOW:'.CLEAN_RECIPE')
	END
END

RETURN


* * * * * * *
LUSurfScanRecipe:
* * * * * * *

ToolClassCode = 'TENCOR' 	;* Only tool class for Surface Scans

SSRecipes = XLATE('TOOL_CLASS',ToolClassCode,TOOL_CLASS_RECIPES$,'X')

TypeOver = ''
TypeOver<PDISPLAY$> = SSRecipes

NewRecipes = Popup(@WINDOW,TypeOver,'SURF_SCAN_RECIPES')

IF NewRecipes = '' THEN RETURN

CurrRecipeArray = Get_Property(@WINDOW:'.SURFSCAN_RECIPE','DEFPROP')

CurrRecipes = CurrRecipeArray<COL$SURFSCAN_RECIPE>	;* 1st column is the Recipe ID's

ctCnt = COUNT(CurrRecipes,@VM) + (CurrRecipes NE '')

FOR I = 1 TO ctCnt
	CurrRecipe = CurrRecipes<1,I>
	IF CurrRecipe NE '' THEN
		LOCATE CurrRecipe IN NewRecipes USING @VM SETTING Pos THEN
			NewRecipes = DELETE(NewRecipes,1,Pos,0)
		END
	END ELSE
		CurrRecipes<1,I> = NewRecipes[1,@VM]
		NewRecipes[1,COL2()] = ''
	END
NEXT I

IF NewRecipes NE '' THEN
	IF CurrRecipes = '' THEN
		CurrRecipes = NewRecipes
	END ELSE
		CurrRecipes := @VM:NewRecipes
	END
END

Set_Property(@WINDOW:'.SURFSCAN_RECIPE','DEFPROP',CurrRecipes)
*Send_Event(@WINDOW:'.SURFSCAN_RECIPE','CALCULATE',COL$CLEAN_TOOL_DESC)


GOSUB Refresh


RETURN


* * * * * * * *
SurfscanDefaults:
* * * * * * * *

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

IF Stage = 'FWI' OR Stage = 'LWI' THEN Stage = 'WFR'

BEGIN CASE
	CASE Stage = 'PRE' AND EntID = @WINDOW:'.VIRGIN_DEFAULTS'
		Vals = ''
		Vals<COL$LPD>			= '10'
		Vals<COL$SCRATCHES>		= '1'
		Vals<COL$SCRATCH_LEN>	= '1'
		Vals<COL$PITS>			= '1'
		Vals<COL$MOUNDS>		= '1'
		Vals<COL$STACK_FAULTS>	= ''
		Vals<COL$SPIKES>		= ''
		Vals<COL$SPOTS>			= '1'
		Vals<COL$FOV>			= '1'
		Vals<COL$BL_DEFECTS	>	= '1'
		
		CheckVals				= '0':@RM:'1'
		
	CASE Stage = 'PRE' AND EntID = @WINDOW:'.BL_DEFAULTS'
		Vals = ''
		Vals<COL$LPD>			= '10'
		Vals<COL$SCRATCHES>		= '1'
		Vals<COL$SCRATCH_LEN>	= '1'
		Vals<COL$PITS>			= '10'
		Vals<COL$MOUNDS>		= '10'
		Vals<COL$STACK_FAULTS>	= ''
		Vals<COL$SPIKES>		= ''
		Vals<COL$SPOTS>			= '5'
		Vals<COL$FOV>			= '2'
		Vals<COL$BL_DEFECTS	>	= '10'
		
		CheckVals				= '1':@RM:'1'
		
	CASE Stage = 'WFR' AND EntID = @WINDOW:'.VIRGIN_DEFAULTS'
		Vals = ''
		Vals<COL$LPD>			= '20'
		Vals<COL$SCRATCHES>		= '1'
		Vals<COL$SCRATCH_LEN>	= '1'
		Vals<COL$PITS>			= '1'
		Vals<COL$MOUNDS>		= '1'
		Vals<COL$STACK_FAULTS>	= '10'
		Vals<COL$SPIKES>		= '5'
		Vals<COL$SPOTS>			= '1'
		Vals<COL$FOV>			= '1'
		Vals<COL$BL_DEFECTS	>	= '1'
		
		CheckVals				= '1':@RM:'1'

	CASE Stage = 'WFR' AND EntID = @WINDOW:'.BL_DEFAULTS'
		Vals = ''
		Vals<COL$LPD>			= '20'
		Vals<COL$SCRATCHES>		= '1'
		Vals<COL$SCRATCH_LEN>	= '10'
		Vals<COL$PITS>			= '20'
		Vals<COL$MOUNDS>		= '20'
		Vals<COL$STACK_FAULTS>	= '20'
		Vals<COL$SPIKES>		= '5'
		Vals<COL$SPOTS>			= '1'
		Vals<COL$FOV>			= '1'
		Vals<COL$BL_DEFECTS	>	= '20'
		
		CheckVals				= '1':@RM:'1'
		
	CASE 1
		RETURN

END CASE

CurrVals = Get_Property(@WINDOW:'.VISUAL_PARMS','LIST')<1>

CONVERT @VM TO '' IN CurrVals

Response = 1
IF LEN(TRIM(CurrVals)) AND CurrVals NE 0 THEN

	MsgInfo = ''
	MsgText = 'There is already data Visual Inspect section...':CrLf$:'Do you wish to overwrite with the standards?'
	MsgInfo<MTEXT$> = MsgText
	MsgInfo<MICON$> = '?'
	MsgInfo<MTYPE$> = 'BNY'
	Response = Msg( @WINDOW, MsgInfo )
END

IF Response THEN
	
	CheckCtrls = @WINDOW:'.MICROSCOPE':@RM:@WINDOW:'.BRIGHTLIGHT'
	CheckProps = 'CHECK':@RM:'CHECK'

	Set_Property(CheckCtrls,CheckProps,CheckVals)

	vpList = ''
	FOR I = 1 TO 10
		vpList<1,I> = Vals<I>
	NEXT I

	Set_Property(@WINDOW:'.VISUAL_PARMS','LIST',vpList)
	
END 

RETURN


* * * * * * *
PropertyDC:
* * * * * * *

PSNo = Get_Property(@WINDOW:'.PS_NO','DEFPROP')
LayerNo	= Get_Property(@WINDOW:'.LAYER_NO','DEFPROP')

IF PSNo = '' THEN RETURN
IF LayerNo = '' THEN RETURN

CtrlEntID = @WINDOW:'.PRS_PROP_KEY'
CurrPos = Get_Property(CtrlEntID,'SELPOS')
CurrCol = CurrPos<1>
CurrRow = CurrPos<2>


IF CurrCol = COL$MET_PROP THEN
	PropCd = Get_Property(CtrlEntID,'CELLPOS',COL$MET_PROP:@FM:CurrRow)

	IF PropCd NE '' THEN
				
		Send_Event(@WINDOW,'WRITE')

		DetWindow	= 'PRS_PROP'
		DetKeys		= PSNo:'*':LayerNo:'*':PropCd
		DefaultRec	= ''
		RetKey		= PSNo:'*':LayerNo
		RetPage		= 1
		RetCtrl		= CtrlEntID
		RetPos		= CurrPos

		oAParms = DetWindow:@RM:DetKeys:@RM:DefaultRec:@RM:RetKey:@RM:RetPage:@RM:RetCtrl:@RM:RetPos

		obj_AppWindow('ViewNewDetail',oAParms)
		IF Get_Status(errCode) THEN
			ErrMsg(errCode)
		END

	END
END	;* End of PropCd column

RETURN


* * * * * * *
LURecipe:
* * * * * * *

RecipeNo = Get_Property(@WINDOW:'.RECIPE','DEFPROP')



Option = Msg(@WINDOW,'','RECIPE_OPTIONS')						; * Select, Create New or Cancel

BEGIN CASE
	CASE Option = 1
		RecID = Popup(@WINDOW,'','CHOOSE_RECIPE')					;* Select List
	CASE Option = 2
		IF RecipeNo = '' THEN
			Void = Start_Window( 'RECIPE', @WINDOW, '*Choosing', '', '' )
		END ELSE
			Void = Start_Window( 'RECIPE', @WINDOW, RecipeNo:'*CENTER', '', '' )
		END
	CASE 1
		RETURN
END CASE


IF RecipeNo NE '' THEN
	oaParms = RecipeNo:@RM:@WINDOW:'.RECIPE'
	obj_Appwindow('LUValReturn',oaParms)
END


RETURN



* * * * * * *
MetTestPC:
* * * * * * *

PSNo = Get_Property(@WINDOW:'.PS_NO','DEFPROP')

IF PSNo = '' THEN RETURN

* Get Last Layer No

LayerNos = XLATE('PROD_SPEC',PSNo,'LAYER_NO','X')

LOOP
	LayerNo = LayerNos[-1,'B':@VM]
UNTIL LayerNo NE ''
	LayerNos[COL1(),5] = ''
REPEAT

LayerCnt = COUNT(LayerNos,@VM) + (LayerNos NE '')
IF LayerCnt > 1 THEN
	SRhoLayerNo = FIELD(LayerNos,@VM,LayerCnt - 1)
END ELSE
	SRhoLayerNo = LayerNo
END

CtrlEntID = @WINDOW:'.MET_TEST'

PrevPos = Get_Property(CtrlEntID,'PREVSELPOS')
PrevCol = PrevPos<1>

CurrPos = Get_Property(CtrlEntID,'SELPOS')
CurrCol = CurrPos<1>
CurrRow = CurrPos<2>

CurrLine = Get_Property(CtrlEntID,'LIST')<CurrRow>


DefProp = ''
BEGIN CASE		

	CASE CurrCol = COL$MET_TOOL_CLASS 
	
		PropCode	= CurrLine<1,COL$MET_PROP>
		
		OPEN 'DICT.TOOL_CLASS' TO DictVar ELSE
			ErrMsg('Unable to open DICT.TOOL_CLASS in COMM_PRS_STAGE.')
		END

		SearchString  = 'PROP_CD':@VM:PropCode:@FM

		Set_Status(0)

		ToolClasses = ""
		Option = ""
		Flag = ""
		Btree.Extract(SearchString, 'TOOL_CLASS', DictVar, ToolClasses, option, flag)

		IF Get_Status(errCode) THEN
			ErrMsg(errCode)
			RETURN
		END
		
		Send_Message(@WINDOW:'.MET_TEST','COLFORMAT',COL$MET_TOOL_CLASS,@VM:ToolClasses)
	
		RETURN
		
		
	CASE CurrCol = COL$MET_RECIPE OR CurrCol = COL$MET_RECIPE_PATTERN
	
		ToolClass = CurrLine<1,COL$MET_TOOL_CLASS>
		
		ToolClassRec = XLATE('TOOL_CLASS',ToolClass,'','X')
		Recipes		= ToolClassRec<TOOL_CLASS_RECIPES$>
		Patterns	= ToolClassRec<TOOL_CLASS_PATTERN$>
		
		Send_Message(@WINDOW:'.MET_TEST','COLFORMAT',COL$MET_RECIPE,@VM:Recipes)
		Send_Message(@WINDOW:'.MET_TEST','COLFORMAT',COL$MET_RECIPE_PATTERN,@VM:Patterns)
	
		RETURN
		

	CASE CurrCol = COL$MET_MIN AND CurrLine<1,COL$MET_MIN> = ''
		MetTest = CurrLine<1,COL$MET_TEST>
		
		BEGIN CASE
			CASE MetTest = 'THICK_ONLY' OR MetTest = 'ADE'
				DefProp = XLATE('PRS_PROP',PSNo:'*':LayerNo:'*THICK','MIN','X')
				
			CASE MetTest = 'LW_RHO' 
				DefProp = XLATE('PRS_PROP',PSNo:'*':SRhoLayerNo:'*SRES','MIN','X')
				
			CASE MetTest = 'SRP'
				DefProp = XLATE('PRS_PROP',PSNo:'*':LayerNo:'*CONC','MIN','X')
				
		END CASE
		
		
	CASE CurrCol = COL$MET_MAX AND CurrLine<1,COL$MET_MAX> = ''
			
		MetTest = CurrLine<1,COL$MET_TEST>
		
		BEGIN CASE
			CASE MetTest = 'THICK_ONLY' OR MetTest = 'ADE'
				DefProp = XLATE('PRS_PROP',PSNo:'*':LayerNo:'*THICK','MAX','X')
				
			CASE MetTest = 'LW_RHO' 
				DefProp = XLATE('PRS_PROP',PSNo:'*':SRhoLayerNo:'*SRES','MAX','X')
				
			CASE MetTest = 'SRP'
				DefProp = XLATE('PRS_PROP',PSNo:'*':LayerNo:'*CONC','MAX','X')
				
			CASE 1
			
		END CASE
		
END CASE

********************************************************************************************

IF DefProp NE '' THEN
	Set_Property(CtrlEntId,"CELLPOS",DefProp,CurrCol:@FM:CurrRow)
END

RETURN


* * * * * * *
MetTestLF:
* * * * * * *

PSNo	= Get_Property(@WINDOW:'.PS_NO','DEFPROP')
Stage	= Get_Property(@WINDOW:'.STAGE','DEFPROP')

IF PSNo = '' THEN RETURN
IF Stage = '' THEN RETURN

CtrlEntID	= @WINDOW:'.MET_TEST'
MetList		= Get_Property(CtrlEntID,'LIST')

OrgRec = XLATE('PRS_STAGE',PSNo:'*':Stage,'','X')

LOOP
	TestLine = MetList[-1,'B':@FM]
UNTIL TestLine<1,COL$MET_TEST> NE '' OR MetList = ''
	MetList[COL1(),199] = ''
REPEAT

CurrArray = ''
LineCnt = COUNT(MetList,@FM) + (MetList NE '')


FOR Line = 1 TO LineCnt
	CurrArray<COL$MET_TEST,Line> 			= MetList<Line,COL$MET_TEST>
	CurrArray<COL$MET_RECIPE,Line>			= MetList<Line,COL$MET_RECIPE>
	CurrArray<COL$MET_RECIPE_PATTERN,Line>	= MetList<Line,COL$MET_RECIPE_PATTERN>
	CurrArray<COL$MET_MIN,Line>				= MetList<Line,COL$MET_MIN>
	CurrArray<COL$MET_MAX,Line>				= MetList<Line,COL$MET_MAX>
	CurrArray<COL$MET_PHASE_MIN,Line>		= MetList<Line,COL$MET_PHASE_MIN>
	CurrArray<COL$MET_SLOT,Line>			= MetList<Line,COL$MET_SLOT>
	CurrArray<COL$MET_START,Line>			= MetList<Line,COL$MET_START>
	
NEXT Line

Delta = 0

IF OrgRec<PRS_STAGE_MET_TEST$>				NE CurrArray<COL$MET_TEST>				THEN Delta = 1
IF OrgRec<PRS_STAGE_MET_RECIPE$>			NE CurrArray<COL$MET_RECIPE> 			THEN Delta = 1
IF OrgRec<PRS_STAGE_MET_RECIPE_PATTERN$>	NE CurrArray<COL$MET_RECIPE_PATTERN>	THEN Delta = 1
IF OrgRec<PRS_STAGE_MET_MIN$>				NE CurrArray<COL$MET_MIN>				THEN Delta = 1
IF OrgRec<PRS_STAGE_MET_MAX$>				NE CurrArray<COL$MET_MAX>				THEN Delta = 1
IF OrgRec<PRS_STAGE_MET_MAX$>				NE CurrArray<COL$MET_MAX>				THEN Delta = 1
IF OrgRec<PRS_STAGE_MET_PHASE_MIN$>         NE CurrArray<COL$MET_PHASE_MIN>			THEN Delta = 1
IF OrgRec<PRS_STAGE_MET_SLOT$>				NE CurrArray<COL$MET_SLOT>				THEN Delta = 1
IF OrgRec<PRS_STAGE_MET_INTERVAL$>			NE CurrArray<COL$MET_INTERVAL>			THEN Delta = 1
IF OrgRec<PRS_STAGE_MET_START$>				NE CurrArray<COL$MET_START>				THEN Delta = 1


/*
IF Delta THEN

	DEBUG
	
	MsgHead	= 'QA Metrology changed'
	MsgText	= 'Do you wish to update in process WO Material with the new QA Met specification?'

	OK = Msg(@WINDOW,'','YESNO','',MsgHead:@FM:MsgText)

	IF OK = 1 THEN
		OPEN 'DICT.WO_MAT' TO DictVar ELSE
			ErrMsg('Unable to open "DICT.WO_MAT" for Btree.Extract')
			RETURN
		END
		
		Search	 = 'SAP_BATCH_NO':@VM:'=':@FM				;* SAP_BATCH_NO = null
		Search	:= 'WO_STEP_PS_NO':@VM:'[':PSNo:']':@FM		;* WO_STEP_PS_NO contains PSNo
		Options  = ''
		Flag 	 = ''
		
		Btree.Extract(Search,'WO_MAT',DictVar,WOMatKeys,Options,Flag)
		
		IF Get_Status(errCode) THEN
			ErrMsg(errCode)
			RETURN
		END
	
		DEBUG
	END

END	;* End of check for delta
*/

RETURN


* * * * * * *
LUToolClass:
* * * * * * *

ClassCd = Popup(@WINDOW,'','TOOL_CLASS')

IF ClassCD NE '' THEN
	oaParms = ClassCd:@RM:@WINDOW:'.PROC_TOOL_CLASS'
	obj_Appwindow('LUValReturn',oaParms)
END


RETURN


* * * * * * *
LUAction:
* * * * * * *

TypeOver = ''
TypeOver<PSELECT$> = 3	;* Ordered Multiple Select

Actions = Popup(@WINDOW,TypeOver,'WO_MAT_INV_ACTION')

IF Actions = '' OR Actions = CHAR(27)  THEN RETURN

RetCtrlEntID = @WINDOW:'.ACTION'

Set_Property(RetCtrlEntID,'DEFPROP',Actions:@VM:@VM)




RETURN

* * * * * * * *
RequiredFields:
* * * * * * * *
    
    Stage = Get_Property(@Window: '.STAGE', 'DEFPROP')
    
    Begin Case
        Case Stage EQ 'PRE'
            GoSub   CheckCleansFields
            GoSub   CheckVisualFields
        Case Stage EQ 'FWI'
            GoSub   CheckVisualFields
        Case Stage EQ 'LWI'
            GoSub   CheckVisualFields
            GoSub   CheckSurface
        Case Stage EQ 'POST'
            GoSub   CheckCleansFields
            GoSub CheckSurface
        Case Stage EQ 'QA'
            GoSub   CheckQAFields
        Case Stage EQ 'UNLOAD'
            GoSub   CheckQAFields
    End Case
    
return

* * * * * * *
ResetColors:
* * * * * * *
    Set_Property(@Window: '.CLEAN_SIG_REQ', 'BACKCOLOR', GREY_BACK$)
    Set_Property(@Window: '.INSP_SIG_REQ', 'BACKCOLOR', GREY_BACK$)
    Set_Property(@Window: '.SURFSCAN_REQ', 'BACKCOLOR', GREY_BACK$)
    Set_Property(@Window: '.SURFSCAN_RECIPE', 'BACKCOLOR', WHITE$)
    Set_Property(@Window: '.CLEAN_TOOL', 'BACKCOLOR', WHITE$)
    Set_Property(@Window: '.CLEAN_RECIPE', 'BACKCOLOR', WHITE$)
    Set_Property(@Window: '.MICROSCOPE', 'BACKCOLOR', GREY_BACK$)
    Set_Property(@Window: '.BRIGHTLIGHT', 'BACKCOLOR', GREY_BACK$)
    Set_Property(@Window: '.VISUAL_PARMS', 'BACKCOLOR', WHITE$)
    Set_Property(@Window: '.BSIDE_PARMS', 'BACKCOLOR', WHITE$)
    Set_Property(@Window: '.CLEAN_RECIPE', 'BACKCOLOR', WHITE$)
    Set_Property(@Window: '.MET_TEST', 'BACKCOLOR', WHITE$)
    
return

* * * * * * * *
CheckCleansFields:
* * * * * * * *    
    IF Get_Property(@Window: '.CLEAN_SIG_REQ', 'DEFPROP') EQ 0 then
        Set_Property(@Window: '.CLEAN_SIG_REQ', 'BACKCOLOR', RED$)
    end else
        Set_Property(@Window: '.CLEAN_SIG_REQ', 'BACKCOLOR', GREY_BACK$)
    end
    CleanToolTable = Get_Property(@Window: '.CLEAN_TOOL', 'ARRAY')
    IF CleanToolTable<1,1> EQ '' then
        Set_Property(@Window: '.CLEAN_TOOL', 'BACKCOLOR', RED$)
    end else
        Set_Property(@Window: '.CLEAN_TOOL', 'BACKCOLOR', WHITE$)
    end
    test =Get_Property(@Window: '.CLEAN_RECIPE', 'DEFPROP')
    IF Get_Property(@Window: '.CLEAN_RECIPE', 'DEFPROP') EQ '' then
        Set_Property(@Window: '.CLEAN_RECIPE', 'BACKCOLOR', RED$)
    end else
        Set_Property(@Window: '.CLEAN_RECIPE', 'BACKCOLOR', WHITE$)
    end 
    
    
return

CheckVisualFields:
    
    IF Get_Property(@Window: '.INSP_SIG_REQ', 'DEFPROP') EQ 0 then
        Set_Property(@Window: '.INSP_SIG_REQ', 'BACKCOLOR', RED$)
    end else
        Set_Property(@Window: '.INSP_SIG_REQ', 'BACKCOLOR', GREY_BACK$)
    end
    test = Get_Property(@Window: '.MICROSCOPE', 'DEFPROP')
    IF Get_Property(@Window: '.MICROSCOPE', 'DEFPROP') EQ 0 then
        Set_Property(@Window: '.MICROSCOPE', 'BACKCOLOR', RED$)
    end else
        Set_Property(@Window: '.MICROSCOPE', 'BACKCOLOR', GREY_BACK$)
    end
    IF Get_Property(@Window: '.BRIGHTLIGHT', 'DEFPROP') EQ 0 then
        Set_Property(@Window: '.BRIGHTLIGHT', 'BACKCOLOR', RED$)
    end else
        Set_Property(@Window: '.BRIGHTLIGHT', 'BACKCOLOR', GREY_BACK$)
    end
    //FrontSide Parms
    FSTable = Get_Property(@WINDOW: '.VISUAL_PARMS', 'DEFPROP')
    //LPD
    IF FSTable<1> EQ '' then
        Send_Message(@WINDOW: '.VISUAL_PARMS','COLOR_BY_POS',1,1,RED$)
    end else
        Send_Message(@WINDOW: '.VISUAL_PARMS','COLOR_BY_POS',1,1,WHITE$)
    end
    //Scratches
    IF FSTable<2> EQ '' then
        Send_Message(@WINDOW: '.VISUAL_PARMS','COLOR_BY_POS',2,1,RED$)
    end else
        Send_Message(@WINDOW: '.VISUAL_PARMS','COLOR_BY_POS',2,1,WHITE$)
    end
    //Scratch Length
    IF FSTable<3> EQ '' then
        Send_Message(@WINDOW: '.VISUAL_PARMS','COLOR_BY_POS',3,1,RED$)
    end else
        Send_Message(@WINDOW: '.VISUAL_PARMS','COLOR_BY_POS',3,1,WHITE$)
    end
    //Pits
    IF FSTable<4> EQ '' then
        Send_Message(@WINDOW: '.VISUAL_PARMS','COLOR_BY_POS',4,1,RED$)
    end else
        Send_Message(@WINDOW: '.VISUAL_PARMS','COLOR_BY_POS',4,1,WHITE$)
    end
    //Mounds
    IF FSTable<5> EQ '' then
        Send_Message(@WINDOW: '.VISUAL_PARMS','COLOR_BY_POS',5,1,RED$)
    end else
        Send_Message(@WINDOW: '.VISUAL_PARMS','COLOR_BY_POS',5,1,WHITE$)
    end
    //Spots
    IF FSTable<8> EQ '' then
        Send_Message(@WINDOW: '.VISUAL_PARMS','COLOR_BY_POS',8,1,RED$)
    end else
        Send_Message(@WINDOW: '.VISUAL_PARMS','COLOR_BY_POS',9,1,WHITE$)
    end
    //FOV
    IF FSTable<9> EQ '' then
        Send_Message(@WINDOW: '.VISUAL_PARMS','COLOR_BY_POS',9,1,RED$)
    end else
        Send_Message(@WINDOW: '.VISUAL_PARMS','COLOR_BY_POS',9,1,WHITE$)
    end
    //BLDefects
    IF FSTable<10> EQ '' then
        Send_Message(@WINDOW: '.VISUAL_PARMS','COLOR_BY_POS',10,1,RED$)
    end else
        Send_Message(@WINDOW: '.VISUAL_PARMS','COLOR_BY_POS',10,1,WHITE$)
    end
    //BackSide Parms
    BSTable = Get_Property(@WINDOW: '.BSIDE_PARMS', 'ARRAY')
    IF BSTable<1> EQ '' then
        Send_Message(@WINDOW: '.BSIDE_PARMS','COLOR_BY_POS',1,1,RED$)
    end else
        Send_Message(@WINDOW: '.BSIDE_PARMS','COLOR_BY_POS',1,1,WHITE$)
    end
    IF BSTable<2> EQ '' then
        Send_Message(@WINDOW: '.BSIDE_PARMS','COLOR_BY_POS',2,1,RED$)
    end else
        Send_Message(@WINDOW: '.BSIDE_PARMS','COLOR_BY_POS',2,1,WHITE$)
    end
return

CheckSurface:
    IF Get_Property(@Window: '.SURFSCAN_REQ', 'DEFPROP') EQ 0 then
        Set_Property(@Window: '.SURFSCAN_REQ', 'BACKCOLOR', RED$)
    end else
        Set_Property(@Window: '.SURFSCAN_REQ', 'BACKCOLOR', GREY_BACK$)
        
    end
    SSTable = Get_Property(@WINDOW: '.SURFSCAN_RECIPE', 'ARRAY')
    IF SSTable<1> EQ '' then
        Set_Property(@Window: '.SURFSCAN_RECIPE', 'BACKCOLOR', RED$)
    end else
        Set_Property(@Window: '.SURFSCAN_RECIPE', 'BACKCOLOR', WHITE$)
        For SSRecipe = 1 To DCOUNT(SSTable<1>,@VM)
            //DefectCount
            IF SSTable<2, SSRecipe> EQ '' then
                Send_Message(@WINDOW: '.SURFSCAN_RECIPE','COLOR_BY_POS',2,SSRecipe,RED$)
            end else
                Send_Message(@WINDOW: '.SURFSCAN_RECIPE','COLOR_BY_POS',2,SSRecipe,WHITE$)
            end
            //Haze
            IF SSTable<3, SSRecipe> EQ '' then
                Send_Message(@WINDOW: '.SURFSCAN_RECIPE','COLOR_BY_POS',3,SSRecipe,RED$)
            end else
                Send_Message(@WINDOW: '.SURFSCAN_RECIPE','COLOR_BY_POS',3,SSRecipe,WHITE$)
            end
            //Sample Size
            IF SSTable<4, SSRecipe> EQ '' then
                Send_Message(@WINDOW: '.SURFSCAN_RECIPE','COLOR_BY_POS',4,SSRecipe,RED$)
            end else
                Send_Message(@WINDOW: '.SURFSCAN_RECIPE','COLOR_BY_POS',4,SSRecipe,WHITE$)
            end
        Next SSRecipe
    end
return

CheckQAFields:
    
    MetTestLines = Get_Property(@Window: '.MET_TEST', 'ARRAY')
    IF MetTestLines<1,1> EQ '' then
        Set_Property(@Window: '.MET_TEST', 'BACKCOLOR', RED$)
    end else
        Set_Property(@Window: '.MET_TEST', 'BACKCOLOR', WHITE$)
        For MetTestLine = 1 To DCOUNT(MetTestLines<1>, @VM)
            IF MetTestLines<1, MetTestLine> NE '' then
                //Tool Class
                IF MetTestLines<4, MetTestLine> EQ '' then
                    Send_Message(@WINDOW: '.MET_TEST','COLOR_BY_POS',4,MetTestLine,RED$)
                end else
                    Send_Message(@WINDOW: '.MET_TEST','COLOR_BY_POS',4,MetTestLine,WHITE$)
                end
                //Tool Recipe
                IF MetTestLines<5, MetTestLine> EQ '' then
                    Send_Message(@WINDOW: '.MET_TEST','COLOR_BY_POS',5,MetTestLine,RED$)
                end else
                    Send_Message(@WINDOW: '.MET_TEST','COLOR_BY_POS',5,MetTestLine,WHITE$)
                end
                //Tool Recipe Pattern
                IF MetTestLines<6, MetTestLine> EQ '' then
                    Send_Message(@WINDOW: '.MET_TEST','COLOR_BY_POS',6,MetTestLine,RED$)
                end else
                    Send_Message(@WINDOW: '.MET_TEST','COLOR_BY_POS',6,MetTestLine,WHITE$)
                end
                //Measurement Minimum
                IF MetTestLines<7, MetTestLine> EQ '' then
                    Send_Message(@WINDOW: '.MET_TEST','COLOR_BY_POS',7,MetTestLine,RED$)
                end else
                    Send_Message(@WINDOW: '.MET_TEST','COLOR_BY_POS',7,MetTestLine,WHITE$)
                end
                //Measurement Maximum
                IF MetTestLines<8, MetTestLine> EQ '' then
                    Send_Message(@WINDOW: '.MET_TEST','COLOR_BY_POS',8,MetTestLine,RED$)
                end else
                    Send_Message(@WINDOW: '.MET_TEST','COLOR_BY_POS',8,MetTestLine,WHITE$)
                end
                //Measurement Slot
                IF MetTestLines<10, MetTestLine> EQ '' then
                    Send_Message(@WINDOW: '.MET_TEST','COLOR_BY_POS',10,MetTestLine,RED$)
                end else
                    Send_Message(@WINDOW: '.MET_TEST','COLOR_BY_POS',10,MetTestLine,WHITE$)
                end
                //Measurement Qty
                IF MetTestLines<11, MetTestLine> EQ '' then
                    Send_Message(@WINDOW: '.MET_TEST','COLOR_BY_POS',11,MetTestLine,RED$)
                end else
                    Send_Message(@WINDOW: '.MET_TEST','COLOR_BY_POS',11,MetTestLine,WHITE$)
                end
                //Measurement Interval
                IF MetTestLines<13, MetTestLine> EQ '' then
                    Send_Message(@WINDOW: '.MET_TEST','COLOR_BY_POS',12,MetTestLine,RED$)
                end else
                    Send_Message(@WINDOW: '.MET_TEST','COLOR_BY_POS',12,MetTestLine,WHITE$)
                end
                //Measurement Start
                IF MetTestLines<14, MetTestLine> EQ '' then
                    Send_Message(@WINDOW: '.MET_TEST','COLOR_BY_POS',13,MetTestLine,RED$)
                end else
                    Send_Message(@WINDOW: '.MET_TEST','COLOR_BY_POS',13,MetTestLine,WHITE$)
                end
                //CRES Parameters
                IF MetTestLines<1, MetTestLine> EQ 'CRES' then
                    //Phase
                    If MetTestLines<9, MetTestLine> EQ '' then
                        Send_Message(@WINDOW: '.MET_TEST','COLOR_BY_POS',9,MetTestLine,RED$)
                    end else
                        Send_Message(@WINDOW: '.MET_TEST','COLOR_BY_POS',9,MetTestLine,WHITE$) 
                    end
                    //R Sched
                    If MetTestLines<12, MetTestLine> EQ '' then
                        Send_Message(@WINDOW: '.MET_TEST','COLOR_BY_POS',12,MetTestLine,RED$)
                    end else
                        Send_Message(@WINDOW: '.MET_TEST','COLOR_BY_POS',12,MetTestLine,WHITE$) 
                    end
                end
            end
        Next MetTestLine
    end
return


