compile function prod_spec_comm(Branch)
begin condition
pre:
post:
end condition

$insert quote_spec_equ
$insert quote_sigs_equ
$insert recipe_equ
$insert recipe_layer_info_equ
$insert msg_equates
$insert logical
$insert shipping_info_equ
$insert TOOL_CLASS_EQUATES

equ CrLf$ to char(13):char(10)

declare function memberof, scroll_enable

ReturnVar = 0
declare function set_property, fieldcount, get_property, msg, editcell, send_event, dialog_box
declare subroutine create_note
Branches = 'LOAD_SURFACE_DEF,SET_MEASURE,LOAD_TOOL_RECIPE,LOAD_TOOL_PATTERN,SURFSCAN_CLICK,VALIDATE_DOPANT,VALIDATE_MINMAX,SET_SCANNED_IMAGE,VALIDATE_RECIPE,AKRION_RECIPE_CHECK,TW_TYPE_CHECK'
convert ',' to @fm in Branches
locate Branch in Branches using @fm setting Bpos then
   on Bpos gosub load_surface_def, set_measure, load_tool_recipe, load_tool_pattern, surfscan_click, validate_dopant, validate_minmax, set_scanned_image, validate_recipe, akrion_recipe_check, tw_type_check
end else
   Void = msg( '', 'Invalid Branch ':Bpos:' passed to prod_spec_comm' )
end
return ReturnVar
*===========================================================================*
load_surface_def:
	PrePost  = get_property( @window, '@PrePost' )
	VirginBL = get_property( @window, '@VirginBL' )
	* THESE ARE EQUATES VALUES GIVEN TO ME BY CHRIS HILDERBRAND, HE SAID THAT
	* THEY WOULD NOT CHANGE VERY OFTEN, SO HE DOES NOT NEED CONTROL.
	PreVirgin  = '1/1/1/1/1/1/1/10/0/1'
	PostVirgin = '1/1/1/20/1/1/5/2/1/20/1/1'
	PreBL      = '10/10/10/5/2/1/1/10/1/1'
	PostBL     = '20/20/20/20/1/1/5/1/1/20/1/1'
	convert '/' to @rm in PreVirgin
	convert '/' to @rm in PostVirgin	
	convert '/' to @rm in PreBL
	convert '/' to @rm in PostBL
	*
	PrePrompts = 'PRE_PITS/PRE_MOUNDS/PRE_BL_DEFECTS/PRE_SPOTS/PRE_FOV/PRE_SCRATCHES/PRE_SCRATCH_LEN/PRE_LPD/PRE_MICROSCOPE/PRE_BRIGHTLIGHT'
	swap '/' with @rm:@window:'.' in PrePrompts
	PrePrompts = @window:'.':PrePrompts
	*
	PostPrompts = 'POST_PITS/POST_MOUNDS/POST_BL_DEFECTS/POST_STACK_FAULTS/POST_SPOTS/POST_FOV/'
	PostPrompts:= 'POST_SPIKES/POST_SCRATCHES/POST_SCRATCH_LEN/POST_LPD/POST_MICROSCOPE/POST_BRIGHTLIGHT'
	*
	swap '/' with @rm:@window:'.' in PostPrompts
	PostPrompts = @window:'.':PostPrompts
	if PrePost = 'PRE' then
		ControlsToUse = PrePrompts 
		if VirginBL = 'VIRGIN' then
			StandardToUse = PreVirgin
			MsgText = ' Pre Epi Virgin '
		end else
			StandardToUse = PreBL
			MsgText = ' Pre Epi Buried Layer '			
		end
	end else
		ControlsToUse = PostPrompts
		if VirginBL = 'VIRGIN' then
			StandardToUse = PostVirgin
			MsgText = ' Post Epi Virgin '			  				
		end else
			StandardToUse = PostBL
			MsgText = ' Post Epi Buried Layer '
		end
	end
	* SEE IF ALL FIELDS ARE BLANK, OTHERWISE NOTIFY USER THAT THEY ARE
	* ABOUT TO OVERWRITE, GIVING THEM A CHANCE TO CANCEL 
	CurrentValues = get_property( ControlsToUse, 'INVALUE' )
	convert @rm to '' in CurrentValues
	OverWrite = true$
	 
	if len( trim( CurrentValues ) ) and ( CurrentValues <> 0 ) then
	   * CURRENT VALUES WILL BE ZERO IF THER IS NO DATA DUE TO MICROSCOPE BEING 
	   * ZERO IF NOT CHECKED
	   MsgInfo = ''
	   MsgText = 'There is already data in the':MsgText:'section...':CrLf$:'Do you wish to overwrite with the standards?'
	   MsgInfo<mtext$> = MsgText
	   MsgInfo<micon$> = '?'
	   MsgInfo<mtype$> = 'BNY'
	   OverWrite = msg( '', MsgInfo )
	end
	*
	if OverWrite then
		Void = set_property( ControlsToUse, 'INVALUE', StandardToUse )
		if StandardToUse = PostBL and PrePost = 'POST' then
			* SET MICROSCOPE FOR POST EPI AREA
			Void = set_property( @window:'.CLEAN_BRIGHTLIGHT', 'INVALUE', 1 )
		end
	end
return
*============================================================================*
SET_MEASURE:
   CtrlToSet = get_property( @window, '@MeasureToSet' )
   MType = get_property( @window, '@MeasureType' )
   MDesc = get_property( @window, '@MeasureDesc' )
   ParamToPass = get_property( @window:'.':CtrlToSet, 'TEXT' )
   HoldParamToPass = ParamToPass
	RetVar = dialog_box( 'PROD_SPEC_SI4', @window, ParamToPass:char(245):MType:char(245):MDesc:char(245):'CENTER' )
	if ( RetVar <> HoldParamToPass ) and ( RetVar <> '' ) then
		Void = set_property( @window:'.':CtrlToSet, 'TEXT', RetVar )
	end
return
*============================================================================*
LOAD_TOOL_RECIPE:
   Tool = get_property( @window:'.TOOL', 'TEXT' )
   convert @lower_case to @upper_case in Tool
	RecipeList = xlate( 'TOOL_CLASS', Tool, TOOL_CLASS_RECIPES$, 'X' )
	convert @vm to @fm in RecipeList
	if RecipeList <> '' then
	   Void = set_property( @window:'.RECIPE', 'LIST', RecipeList )
	end
return
*============================================================================*
*============================================================================*
LOAD_TOOL_PATTERN:
   Tool = get_property( @window:'.TOOL', 'TEXT' )
   convert @lower_case to @upper_case in Tool
	PatternList = Xlate('TOOL_CLASS', Tool, TOOL_CLASS_PATTERN$, 'X')
	CONVERT @VM To @FM IN PatternList
	If PatternList Ne '' Then
		 Void = Set_Property(@Window:'.PATTERN', 'LIST', PatternList)
	End
return
*============================================================================*
SURFSCAN_CLICK:
   CtrlToUse = get_property( @window, '@SurfScanCtl' )
   if get_property( @window:'.':CtrlToUse, 'CHECK' ) then
      Void = set_property( @window:'.':CtrlToUse:"_RECIPE", "ENABLED", 1 )
      Void = set_property( @window:'.':CtrlToUse:"_DEFECTS", "ENABLED", 1 )
      Void = set_property( @window:'.':CtrlToUse:"_HAZE", "ENABLED", 1 )                  
   end else
      Void = set_property( @window:'.':CtrlToUse:"_RECIPE", "TEXT", '' )
      Void = set_property( @window:'.':CtrlToUse:"_DEFECTS", "TEXT", '' )
      Void = set_property( @window:'.':CtrlToUse:"_HAZE", "TEXT", '' )         
      Void = set_property( @window:'.':CtrlToUse:"_RECIPE", "ENABLED", 0 )
      Void = set_property( @window:'.':CtrlToUse:"_DEFECTS", "ENABLED", 0 )
      Void = set_property( @window:'.':CtrlToUse:"_HAZE", "ENABLED", 0 )      
   end
return
*============================================================================*
VALIDATE_DOPANT:
   PSNDopant = get_property( @window:'.EPI_DOPANT', 'TEXT' )
   LayerOn = get_property( @window, '@LayerOn' )
   RecipeID = get_property( 'PROD_SPEC_SI.EPI_RECIPE', 'TEXT' )
   if ( RecipeID <> '' ) and ( PSNDopant <> '' ) then
      if LayerOn = 1 then
         RecipeDopant = xlate( 'RECIPE', RecipeID, recipe_epi_dopant$, 'X' )
      end else
         RecLayInfo = xlate( 'RECIPE', RecipeID, recipe_layer_info$, 'X' )
         RecipeDopant = RecLayInfo<1,RecLEpiDopant$>      
      end
      if PSNDopant = RecipeDopant then
         * IT VALIDATED OK - THE DOPANTS MATCH
         ReturnVar = 1
      end else
         MsgInfo = ''
         MsgInfo<mtext$> = 'The ':quote(PSNDopant):' dopant does not match the recipe dopant.'
         MsgInfo<micon$> = 'H'
         Void = msg( '', MsgInfo )
         ReturnVar = 0 
      end
   end else
      ReturnVar = 1
   end
return
*============================================================================*
VALIDATE_MINMAX:
   * NEED TO MAKE SURE THE MIN IS LESS THAN THE MAX
   MinThick = get_property( @window:'.EPI_MIN_THICK', 'TEXT' )
   MaxThick = get_property( @window:'.EPI_MAX_THICK', 'TEXT' )
   MinRes   = get_property( @window:'.EPI_RES_MIN_THICK', 'TEXT' )
   MaxRes   = get_property( @window:'.EPI_RES_MAX_THICK', 'TEXT' )
   if ( MaxThick < MinThick ) or ( MaxRes < MinRes ) then
      MsgInfo = ''
      MsgInfo<mtext$> = 'You can not have a maximum tolerance value that is less than your minimum tolerance value.'
      MsgInfo<micon$> = 'H'
      Void = msg( '', MsgInfo )
      ReturnVar = 0 
   end else
      ReturnVar = 1
   end
return
*============================================================================*
SET_SCANNED_IMAGE:
	CurArray = get_property( @window:'.SCANNED_INFO', 'ARRAY' )
	CCnt = fieldcount( CurArray, @vm )
	Tcnt = 0
	PVals = 'No Scanned Img'
	for i = 1 to CCnt
	   if ( CurArray<1,i> <> '' ) then
	      Tcnt += 1   
	      PVals<i> = 'Scanned Img ':i
	   end
	next i
	if PVals = 'Scanned Image 1' then
	   * THERE IS ONLY ONE SCANNED IMAGE
	   PVals = 'Scanned Img'
	end
   Void = set_property( @window:'.SCANNED_LIST', 'LIST', Pvals )	
return
*============================================================================*
validate_recipe:
   * THIS IS ONLY CALLED ON THE FIRST LAYER WHEN SAVING
   * TO JUST WARN THE USER IF THIS PSN IN NOT IN THE RECIPE WITH IT'S OWN LIMITS   
   RecipeID = get_property( 'PROD_SPEC_SI.EPI_RECIPE', 'TEXT' )
   if RecipeID <> '' then
	   PSNsInRecipe = xlate( 'RECIPE', RecipeID, recipe_prod_spec_ids$, 'X' )
	   CurPSN = get_property( 'PROD_SPEC.PROD_SPEC_ID', 'TEXT' )
	   * CAN DO THE ABOVE CAUSE THE ONLY WAY IN TO THIS WINDOW IS THROUGH PROD_SPEC
	   locate CurPSN in PSNsInRecipe using @vm setting FPos else
	      MsgInfo = ''
	      MText   = 'This PSN ':quote(CurPSN):' is not set up in recipe ':quote(RecipeID)
	      MText  := " with it's own recipe limits.  If this PSN is activated and goes through the"
	      MText  := ' system without these limits, the system will use the top row limits in the'
	      MText  := ' recipe.  Please notify an engineer to handle this issue.'
	      MsgInfo<mtext$> = MText       
	      MsgInfo<micon$> = '!'
	      Void = msg( '', MsgInfo )
	   end
	   * NO NEED TO SET RETURNVAR CAUSE CALLING CODE DOES NOT CHECK FOR ERROR IT
	   * IS ONLY A WARNING MESSAGE
	end
return
*============================================================================*
akrion_recipe_check:
   SubPreClean = get_property( @window:'.SUB_PRE_CLEAN', 'TEXT' )
   ReturnVar = 1
   if index( SubPreClean,'Akrion', 1 ) then
      PreAkrionRecipe = get_property( @window:'.PRECLEAN_AKRIONRECIPES', 'TEXT' )
      if PreAkrionRecipe = '' then
         MsgInfo = ''
         MsgInfo<mtext$> = 'You must select a pre clean akrion recipe...'
         MsgInfo<micon$> = 'H'
         Void = msg( '', MsgInfo )
         ReturnVar = 0
      end
   end
   SubPostClean = get_property( @window:'.SUB_POST_CLEAN', 'TEXT' )
   if index( SubPostClean, 'Akrion', 1 ) then
      PostAkrionRecipe = get_property( @window:'.POSTCLEAN_AKRIONRECIPES', 'TEXT' )
      if PostAkrionRecipe = '' then
         MsgInfo = ''
         MsgInfo<mtext$> = 'You must select a post clean akrion recipe...'
         MsgInfo<micon$> = 'H'
         Void = msg( '', MsgInfo )
         ReturnVar = 0
      end
   end   
return
*============================================================================*
tw_type_check:
   * THIS CODE WILL CHECK TO SEE IF THE OPPOSITE TYPE OF TEST WAFER IS BEING USED
   * BASICALLY IF YOU CAN NOT FIND BORON IN THE EPI DOPANT THEN ASSUME THAT IT IS N TYPE
   * IF N TYPE SHOULD USE P-TYPE TEST WAFER AND IF P TYPE SHOULD USE N-TYPE TEST WAFER
   CurControl = get_property( @window, '@CurControl' )
   WaferType  = get_property( CurControl, 'TEXT' )
   EpiDopant = get_property( 'PROD_SPEC_SI.EPI_DOPANT', 'TEXT' )
   if len( WaferType ) = 2 then ;* ONLY CHECK FOR P+, P-, N+, N-
	   if index( EpiDopant, 'Boron', 1 ) then
	      * PTYPE
	      * CHECK THE FIRST LETTER FOR N
	      if WaferType[1,1] = 'N' else
	         MsgInfo = ''
	         MsgInfo<mtext$> = 'Warning: The dopant being used is PType, this normally should use an NType test.'
	         MsgInfo<micon$> = '!'
	         Void = msg( '', MsgInfo ) 
	      end
	   end else
	      * NTYPE
	      * CHECK THE FIRST LETTER FOR P
	      if WaferType[1,1] = 'P' else
	         MsgInfo = ''
	         MsgInfo<mtext$> = 'Warning: The dopant being used is NType, this normally should use a PType test.'
  	         MsgInfo<micon$> = '!'
	         Void = msg( '', MsgInfo ) 	          
	      end	      
	   end
   end   
return
*============================================================================*
