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

/*
	Commuter module for Dialog_Split_Wafer window.- Cloned from DIALOG_LOAD_SUSCEPTOR
	
	06/5/2016 - John C. Henry, J.C. Henry & Co., Inc.
*/

DECLARE SUBROUTINE Set_Property, End_Dialog, Set_Status, ErrMsg, obj_RDS2, Send_Event, RDS_React_Run, Send_Info, obj_React_Run, obj_WO_Wfr, obj_Run_Stage
DECLARE SUBROUTINE obj_Appwindow, Start_Window, Msg, End_Dialog, Send_Message, obj_MAT_INBOUND, obj_WM_Wfrs, obj_React_Status, obj_WO_Wfr_WIP, obj_Run_Stage_Wfr
DECLARE FUNCTION Get_Property, Get_Status, Dialog_Box, Popup, obj_WM_In, Send_Message, obj_NCR, obj_WM_Wfrs, Set_Property, obj_WO_Mat_Wfr, obj_WO_Wfr_WIP
DECLARE FUNCTION obj_Prod_Spec, obj_WO_Wfr

EQU CRLF$	TO \0D0A\


$INSERT REACT_RUN_EQUATES
$INSERT REACTOR_EQUATES
$INSERT RDS_TEST_EQUATES
$INSERT TOOL_EQUATES
$INSERT TOOL_CLASS_EQUATES
$INSERT PRS_STAGE_EQUATES
$INSERT WO_LOG_EQUATES
$INSERT WO_STEP_EQUATES
$INSERT WO_MAT_EQUATES
$INSERT APPCOLORS
$INSERT WO_WFR_EQUATES

EQU COL$WFR_ID		TO 1
EQU COL$SCRIBE		TO 2


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


ErrTitle = 'Error in Dialog_Split_Wafer commuter module'
ErrorMsg = ''
ErrCode  = ''

Result = ''


BEGIN CASE

	CASE EntID = @WINDOW
		BEGIN CASE
			CASE Event = 'CREATE' 			; GOSUB Create
			CASE Event = 'CLOSE'			; GOSUB Close			;* This needs to be a PRECLOSE event!
			
			CASE Event[1,3] = 'QBF'			; GOSUB Refresh
		END CASE
	
	CASE EntID = @WINDOW:'.SPLIT_BUTTON'	AND Event = 'CLICK'		; GOSUB SplitWfr	
	CASE EntID = @WINDOW:'.CANCEL_BUTTON'	AND Event = 'CLICK'		; GOSUB Cancel
	
	
	CASE EntID = @WINDOW:'.REACTOR_TABLE'	AND Event = 'INSERTROW'	; GOSUB ReactIR
	CASE EntID = @WINDOW:'.REACTOR_TABLE'	AND Event = 'DELETEROW'	; GOSUB ReactIR
	
	
	
	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')


RDSNo		= FIELD(Parm1,@FM,1)
Stage		= FIELD(Parm1,@FM,2)
ToolID		= FIELD(Parm1,@FM,3)


IF RDSNo = '' THEN 
	ErrMsg('Null RDS No passed to Dialog Box...')
	End_Dialog(@WINDOW,'')
END

RRunRec = XLATE('REACT_RUN',RDSNo,'','X')

WONo		= RRunRec<REACT_RUN_WO_NO$>
WOStep	 	= RRunRec<REACT_RUN_WO_STEP$>
GanRun		= RRunRec<REACT_RUN_GAN_RUN_ID$>


Ctrls  = @WINDOW:'.RDS_NO':@RM			; Props  = 'DEFPROP':@RM	; Vals  = RDSNo:@RM
Ctrls := @WINDOW:'.GAN_RUN':@RM			; Props := 'DEFPROP':@RM	; Vals := GanRun:@RM
Ctrls := @WINDOW:'.STAGE':@RM			; Props := 'DEFPROP':@RM	; Vals := Stage:@RM
Ctrls := @WINDOW:'.TOOL_ID':@RM			; Props := 'DEFPROP':@RM	; Vals := ToolID:@RM
Ctrls := @WINDOW:'.WO_NO':@RM			; Props := 'DEFPROP':@RM	; Vals := WONo:@RM
Ctrls := @WINDOW:'.WO_STEP'				; Props := 'DEFPROP'		; Vals := WOStep

Set_Property(Ctrls,Props,Vals)

LoadCnt = 0
OpenCnt = 0

RCtrl = @WINDOW:'.CARRIER'

CarrWfrIDs	= RRunRec<REACT_RUN_CARR_WFR_ID$>
CarrScribes	= XLATE('WO_WFR',CarrWfrIDs,WO_WFR_SCRIBE$,'X')

Set_Property(RCtrl,'DEFPROP',CarrWfrIDs:@FM:CarrScribes)

clCnt = COUNT(CarrWfrIDs,@VM) + (CarrWfrIDs NE '')


IF clCnt NE 0 THEN

	* Loaded
	
	BriefTxt  = '{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}}'
	BriefTxt := '{\*\generator Msftedit 5.41.15.1515;}\viewkind4\uc1\pard\b\f0\fs20 Split Wafer from Cassette\par'
	BriefTxt := '\b0\par'
	BriefTxt := ' 1.) Split Wafer from Run for Characterization\b\par'
	BriefTxt := '\b0\par'
	BriefTxt := '}'
	
	
	
	Set_Property(@WINDOW:'.BRIEF_EDITBOX','RTFTEXT',BriefTxt)
END ELSE
	ErrMsg('Wafers must be unloaded from the reactor prior to splitting for characterizaton.')
	RETURN
END


WOStepKey = WONo:'*':WOStep

GOSUB Refresh

RETURN



* * * * * * *
SplitWfr:
* * * * * * *

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

ReactNo = XLATE('REACT_RUN',RDSNo,REACT_RUN_REACTOR$,'X')

IF ReactNo = '' THEN
	ErrMsg('Reactor is not yet assigned to this Reactor Run.')
	RETURN
END


CtrlEntID	= @WINDOW:'.CARRIER'

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

SplitComplete = 1


WfrIDArray = Get_Property(CtrlEntID,'DEFPROP')<1>

WfrID		= WfrIDArray<1,CurrRow>

IF WfrID = '' THEN
	ErrMsg('No Wafer ID Selected for Split')
	RETURN
END

* Check for selected WfrID already in the CharWfrID(s)

CharWfrIDs = XLATE('REACT_RUN',RDSNo,REACT_RUN_CHAR_WFR_ID$,'X')

LOCATE WfrID IN CharWfrIDs USING @VM SETTING Pos THEN
	ErrMsg('Wafer ':WfrID:' is already in the Characterization Wafer List')
	RETURN
END


CONVERT @VM TO ' ' IN WfrIDArray

WfrIDArray = TRIM(WfrIDArray)

CONVERT ' ' TO @VM IN WfrIDArray

LOCATE WfrID IN WfrIDArray USING @VM SETTING Pos THEN
	WfrIDArray = DELETE(WfrIDArray,1,Pos,0)
END


PSNo = XLATE('REACT_RUN',RDSNo,'PS_NO','X')

WONo =WfrID[1,'*']
WOMatKey = FIELD(WfrID,'*',1,2)

SigProfile = XLATE('REACT_RUN',RDSNo,REACT_RUN_WFR_STAGE$,'X')

spCnt = COUNT(SigProfile,@VM) + (SigProfile NE '')

FOR I = 1 TO spCnt
	SigStage = SigProfile<1,I>
		
	obj_Run_Stage_Wfr('Create',RDSNo:@RM:SigStage:@RM:WfrID:@RM:PSNo)	;* 6/24/2016 JCH
	
	IF Get_Status(errCode) THEN
		ErrMsg(ErrCode)
		
	END
NEXT I

FirstStage = SigProfile<1,1>

ToolClass = XLATE('PRS_STAGE' , PSNo:'*':FirstStage , PRS_STAGE_PROC_TOOL_CLASS$ , 'X' )

ToolClassRec = XLATE('TOOL_CLASS',ToolClass,'','X')

QInWH = ToolClassRec<TOOL_CLASS_QIN_WH$>
QInLoc = ToolClassRec<TOOL_CLASS_QIN_LOC$>

CurrLocs = obj_WO_Wfr('CurrLoc',WfrID:@RM:'')	;* Added 9/27/2016 JCH	

CurrSlotID	= CurrLocs<1,2>						;* Added 9/27/2016 JCH
CurrTool	= CurrLocs<1,3>						;* Added 9/27/2016 JCH
CurrInvLoc	= CurrLocs<1,4>						;* Added 9/27/2016 JCH


CurrDTM =  OCONV(Date(),'D4/'):' ':OCONV(Time(),'MTS')

owwParms	 = WfrID:@RM					;* WfrIDs - mv
owwParms	:= CurrDTM:@RM					;* EventDtm
owwParms	:= @USER4:@RM					;* EventBy
owwParms	:= 'SPLIT':@RM					;* Event
owwParms	:= '':@RM						;* New Slot IDs - mv
owwParms	:= '':@RM						;* RPZs(RDSNo*Pocket*Zone)s - mv
owwParms	:= '':@RM						;* NCRNo
owwParms	:= '':@RM						;* TWUse ID 
owwParms	:= '':@RM						;* Current Slot ID - mv
owwParms	:= '':@RM						;* New ToolID
owwParms	:= CurrTool:@RM					;* Curr Tool ID						;* This should never happen unless there is missing/incomplete data in the WO_WFR record
owwParms 	:= QInWH:'*':QInLoc:@RM			;* NewInvLoc
owwParms	:= CurrInvLoc:@RM				;* CurrInvLoc
owwParms 	:= 'O':@RM						;* Wfr Side
owwParms	:= '':@RM						;* NewCarrLoc
owwParms	:= ''							;* CurrCarrLoc		;* Not currently used			

obj_WO_Wfr('AddEvent',owwParms)				;* Takes Carrier Loc off and Adds QIn for first Char step

IF Get_Status(errCode) THEN
	ErrMsg(errCode)
	SplitComplete = 0
	RETURN
END


obj_React_Run('SplitWfr',RDSNo:@RM:WfrID)	;* Takes WfrID out of Carr_WfrID, Adds WfrID to Carr_Prev....,  Adds WfrID to CHAR_WFRS

IF Get_Status(errCode) THEN
	ErrMsg(errCode)
	SplitComplete = 0
END


obj_Run_Stage('SetIASig',RDSNo:@RM:'SPLIT':@RM:'SPLIT')		;* Set Inv Action Signature for Action


End_Dialog(@WINDOW,SplitComplete)

IF Stage NE '' THEN
	obj_Appwindow('LoadFormKeys','RUN_STAGE':@RM:RDSNo:'*':Stage)
END


RETURN



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


* * * * * * *
Cancel:
* * * * * * *

RDSNo		= Get_Property(@WINDOW:'.RDS_NO','DEFPROP')
Stage		= Get_Property(@WINDOW:'.STAGE','DEFPROP')
WMILocks	= Get_Property(@WINDOW,'@LOCKED_WFRS')

IF WMILocks NE '' THEN
	obj_WM_Wfrs('UnlockSet','WMI_WFRS':@RM:WMILocks)		; * Remove locks on the wafer slots
END

Set_Property(@WINDOW,'@LOCKED_WFRS','')

End_Dialog(@WINDOW,'')

IF Stage NE  '' THEN
	obj_Appwindow('LoadFormKeys','RUN_STAGE':@RM:RDSNo:'*':Stage)
END

RETURN




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


RETURN




* * * * * * *
ReactIR:
* * * * * * *

RowIndex = Parm1

IF RowIndex = '' THEN RETURN

CtrlID = @WINDOW:'.REACTOR_TABLE'

Dummy = Send_Message(CtrlID,'DELETE',RowIndex)

GOSUB Refresh

RETURN



* * * * * * *
ReactDR:
* * * * * * *

RowIndex = Parm1
RowData = Parm2

IF RowIndex = '' THEN RETURN

CtrlID = @WINDOW:'.REACTOR_TABLE'

Dummy = Send_Message(CtrlID, "INSERT", RowIndex, RowData)

GOSUB Refresh

RETURN





