#!/bin/csh
# This is a program for the example Genesis Tooling Forms.
# This file will exist in form 1.
# The purpose of this program is to help the user set up the layers in the matrix.
# It is called by the "Set-up Matrix" button.
# 
# Written by Ian Ticehurst (Autom8 Ltd.)
# Version 1A. Date: 12.09.00 - Initial design and development.
# Version 1B. Date: 11.12.00 - Add source of info. file to support gui creation.
# Version 1C. Date: 12.12.00 - Re-write the gui windows to use the sourced font and colours.
# Version 1D. Date: 05.02.01 - Modify to only check job path if job moved from original location.
#                            - Add save time update to forms.
# Version 1E. Date: 09.02.01 - Modify the setting and useage of $TMP.
# Version 1F. Date: 14.03.01 - Check how "$GENESIS_EDIR" is set to ensure paths are set correctly.
######################################################################### 

source $_genesis_root/sys/scripts/include_me

set_in_progress genform1 smx

# Close Form
COM close_form,job=$JOB,form=genform1

# Put window on screen asking user to set-up matrix.
o_tooling
o FONT $NORM_FNT
o BG $NORM_COL
o BW 0
o LABEL Job Matrix Pop-up
o LABEL Matrix screen will be opened
o LABEL Program will pause.
o LABEL Complete matrix set-up.
o LABEL Close pause box when matrix finished
o FONT $HINT_FNT
o BG $HINT_COL
o LABEL Hint - Remember to set standard names
o LABEL and then use actions - rearrange rows
o BG $NORM_COL
o END

do_gui

# Open matrix.
COM open_entity,job=$JOB,type=matrix,name=matrix

# Pause script and ask user to complete matrix set-up.
PAUSE Press continue when matrix is done

# Close matrix.
COM matrix_page_close,job=$JOB,matrix=matrix

# Count number of circuit layers in matrix
@ COUNT = 1
@ LAYER_CT = 0
DO_INFO -t matrix -e $JOB/matrix
while ($COUNT <= $#gROWrow)
   if ($gROWcontext[$COUNT] == "board") then
      set ltype = $gROWlayer_type[$COUNT]
      if ("$ltype" == signal || "$ltype" == power_ground || "$ltype" == mixed) then
         @ LAYER_CT ++
      endif
   endif	
   @ COUNT ++
end

if ($LAYER_CT == 0 || $LAYER_CT == 2 || $LAYER_CT == 3) then
   set BTYPE = $LAYER_CT
else
   set BTYPE = 3
endif

# Count number of resist and notation layers in matrix
set COUNT = 1
set RES_LAY = 0
set NOT_LAY = 0
DO_INFO -t matrix -e $JOB/matrix
while ($COUNT <= $#gROWrow)
   if ($gROWcontext[$COUNT] == board) then
      if ($gROWlayer_type[$COUNT] == silk_screen) then
         @ NOT_LAY ++
      else if ($gROWlayer_type[$COUNT] == solder_mask) then
         @ RES_LAY ++
      endif
   endif	
   @ COUNT ++
end

set TMP_DAT = $TMP/smx.$$

# Update resist, notation count, layer and board type on both forms.
echo elem=res_no,value=$RES_LAY >  $TMP_DAT 
echo elem=not_no,value=$NOT_LAY >> $TMP_DAT 
echo elem=lays,value=$LAYER_CT  >> $TMP_DAT
echo elem=btype,value=$BTYPE    >> $TMP_DAT
COM edit_form_list,job=$JOB,form=genform1,in_file=$TMP_DAT
COM edit_form_list,job=$JOB,form=genform2,in_file=$TMP_DAT
\rm -f $TMP_DAT

# Open Form
COM show_form,job=$JOB,form=genform1

set_complete genform1 smx

save_job

exit 0
