#!/bin/csh
# This is a program for the example Genesis Tooling Forms.
# This file will exist in form 2.
# The purpose of this program is to review the results from the final analysis checklist.
# It is called by the "Review Final Analysis Results" 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 genform2 rfr

# Close Form
COM close_form,job=$JOB,form=genform2
source $JOB_PATH/user/info.source

# Open editor on step "pcb".
COM open_entity,job=$JOB,type=step,name=pcb
set group=$COMANS
AUX set_group,group=$group

# Open analysis checklist.
COM chklist_open,chklist=$AN_CHK
COM chklist_show,chklist=$AN_CHK
 
# Pause script and ask user to complete analysis review.
PAUSE Press continue when analysis review is done

# Close editor.
COM editor_page_close

# Put window on screen asking user to provide analysis checklist status.
o_tooling
o FONT $NORM_FNT
o BG $NORM_COL
o BW 0
o LABEL Final Analysis Verification Pop-up.
o LABEL Analysis checklist now reviewed by $USER.
o LABEL "Do you need to perform more editing? - Select relevant option."
o RADIO an_rev Options: V 1 992222
o All circuit editing complete
o Manual editing needs to be rerun
o DFM editing needs to be rerun
o All editing functions need to be rerun
o END

do_gui

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

# Set date for log file entries.

if ($an_rev == 1) then
   # Editing is complete. Check netlist.
   COM netlist_recalc,job=$JOB,step=pcb,type=ref,display=top
   COM netlist_recalc,job=$JOB,step=pcb,type=cur,display=bottom
   COM netlist_compare,job1=$JOB,step1=pcb,type1=ref,job2=$JOB,step2=pcb,type2=cur,display=yes
      
   set SHT = $COMANS[1]
   set BRK = $COMANS[3]
   set MIS = $COMANS[5]
   set EXT = $COMANS[7]

   if ($SHT == 0 && $BRK == 0 && $MIS == 0 && $EXT == 0) then
      # Netlist OK. Mark info.source file as "netlist=pass"
      echo "set NET = 1" >> $JOB_PATH/user/info.source

      # Mark job as OK for panelisation.
      echo "set PAN = 1" >> $JOB_PATH/user/info.source
   
      set_complete genform2 rfr Netlist Check - No Errors
   else
      # Netlist error. Set up window for compare results.
      o_tooling
      o FONT $NORM_FNT
      o BG $WARN_COL
      o BW 0
      o LABEL Netlist Compare Pop-up
      o LABEL Errors found during netlist compare
      o LABEL Results:
      if ($SHT == 0) then
         o BG 007500
      else
         o BG 992233
      endif		
      o LABEL Shorted = $SHT
      if ($BRK == 0) then
         o BG 007500
      else
         o BG 992233
      endif		
      echo LABEL Broken = $BRK
      if ($MIS == 0) then
         o BG 007500
      else
         o BG 992233
      endif		
      o LABEL Missing = $MIS
      if ($EXT == 0) then
         o BG 007500
      else
         o BG 992233
      endif		
      o LABEL Extra = $EXT
      o BG 505050
      o BG $NORM_COL
      o LABEL Netlist screen will now open.
      o LABEL Program will pause.
      o LABEL Identify problem with netlist.
      o LABEL Close Pause Box When Problem Found
      o END

      do_gui

      # Netlist not OK. Mark info.source file as "netlist=fail".
      echo "set NET = 0" >> $JOB_PATH/user/info.source

      COM netlist_page_open,set=no

      # Pause script and ask user to check netlist.
      PAUSE Press continue when netlist problem is identified

      COM netlist_page_close

      # Put window on screen asking user to re-run netlist check or sign off.
      o_tooling
      o FONT $NORM_FNT
      o BG $NORM_COL
      o BW 0
      o LABEL Netlist Sign-off Pop-up.
      o LABEL Netlist errors now reviewed by $USER.
      o LABEL "Do you need to perform more editing? - Select relevant option."
      o RADIO nt_rev Options: V 1 992222
      o Re-run this function
      o All netlist errors fixed
      o Netlist errors exist but have been identified and are no problem
      o END

      do_gui

      if ($nt_rev == 2 || $nt_rev == 3) then
         # Netlist OK. Mark info.source file as "netlist=pass".
         echo "set NET = 1" >> $JOB_PATH/user/info.source

         # Mark job as OK for panelisation.
         echo "set PAN = 1" >> $JOB_PATH/user/info.source
      endif  
      if ($nt_rev == 2) then
         set_complete genform2 rfr Netlist Check - Operator says OK after review
      else
         set_complete genform2 rfr Netlist Check - Operator says false errors only
      endif
   else if ($nt_rev == 1) then
      # User requests to re-run the function.
      # Change colour of action button to show action needs running again.
      COM edit_form,job=$JOB,form=genform2,elem=rfr,value=,color=$RERUN_COLOR,opt_name=yes,callback=no

      # Mark process as complete, but with re-run required.
      COM edit_form,job=$JOB,form=genform2,elem=rfr_dte,value=Rerun function

      # Add line to log to confirm status of action.
      calc_date
      log "END  " "genform2.rfr Netlist check - Operator says Rerun review"
   endif
else if ($an_rev == 2) then
   # Need to re-run manual editing.
   # Change colour of action button to show action needs running again.
   COM edit_form,job=$JOB,form=genform2,elem=rfr,color=$RERUN_COLOR

   # Change colour of manual editing button to show action needs running again.
   COM edit_form,job=$JOB,form=genform2,elem=med,color=$RERUN_COLOR

   # Mark process as complete, but with more editing required.
   COM edit_form,job=$JOB,form=genform2,elem=rfr_dte,value=Rerun manual edits

   # Add line to log to confirm status of action.
   calc_date
   log "END  " genform2.rfr "Netlist check - Review Final results (Rerun manual edits)"
else if ($an_rev == 3) then
   # Need to re-run DFM editing.

   # Change colour of action button to show action needs running again.
   COM edit_form,job=$JOB,form=genform2,elem=rfr,color=$RERUN_COLOR

   # Change colour of dfm editing button to show action needs running again.
   COM edit_form,job=$JOB,form=genform2,elem=dfm,color=$RERUN_COLOR

   # Mark process as complete, but with more editing required.
   COM edit_form,job=$JOB,form=genform2,elem=rfr_dte,value=Rerun DFM edits

   # Add line to log to confirm status of action.
   calc_date
   log "END  " genform2.rfr "Netlist check - Review Final results (Rerun DFM edits)"
else if ($an_rev == 4) then
   # Need to re-run manual editing and DFM editing.

   # Change colour of action button to show action needs running again.
   COM edit_form,job=$JOB,form=genform2,elem=rfr,color=$RERUN_COLOR

   # Change colour of manual editing button to show action needs running again.
   COM edit_form,job=$JOB,form=genform2,elem=med,color=$RERUN_COLOR

   # Change colour of dfm editing button to show action needs running again.
   COM edit_form,job=$JOB,form=genform2,elem=dfm,color=$RERUN_COLOR

   # Mark process as complete, but with more editing required.
   COM edit_form,job=$JOB,form=genform2,elem=rfr_dte,value=Rerun all edits

   # Add line to log to confirm status of action.
   calc_date
   log "END  " genform2.rfr "Netlist check - Review Final results (Rerun all edits)"
endif

save_job

exit 0
