#!/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 to perform CAD netlist compare.
# It is called by the "CAD Netlist Compare" button.
# 
# Written by Ian Ticehurst (Autom8 Ltd.)
# Version 1A. Date: 02.02.01 - Initial design and development.
# Version 1B. Date: 05.02.01 - Modify to only check job path if job moved from original location.
#                            - Text changes to remove abbreviations and ensure American spelling.
#                            - Add save time update to forms.
# Version 1C. Date: 09.02.01 - Modify the setting and useage of $TMP.
# Version 1D. 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 cnc

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

# Create dummy files in input_reports dir. to ensure correct field alignment.
touch $JOB_PATH/user/input_reports/dummy-1
touch $JOB_PATH/user/input_reports/dummy-2

# Check in the input report file to see if CAD netlist supplied and input.
set IN_FORMATS = `grep "Format " $JOB_PATH/user/input_reports/* | awk -F' ' '{print $4}'`
set IN_STEPS = `grep "Step  name" $JOB_PATH/user/input_reports/* | awk -F' ' '{print $5}'`

# Remove dummy files.
\rm $JOB_PATH/user/input_reports/dummy-1
\rm $JOB_PATH/user/input_reports/dummy-2

@ NET_PROC = 0
@ COUNT = 1
foreach IN_FORM ($IN_FORMATS)
   if ($IN_FORM == "Mentor" || $IN_FORM == "IPC356") then
      set NET_PROC = 1
      break
   endif
   @ COUNT ++
end

if ($NET_PROC != 0) then
   # Load cad netlist and run compare (CAD to CURCAD).
   COM netlist_recalc,job=$JOB,step=pcb,type=cad,display=top
   COM netlist_recalc,job=$JOB,step=pcb,type=cur_cad,display=bottom
   COM netlist_compare,job1=$JOB,step1=pcb,type1=cad,job2=$JOB,\
      step2=pcb,type2=cur_cad,display=yes

   set SHORT = "$COMANS[1]"
   set BROKE = "$COMANS[3]"
   set MISS  = "$COMANS[5]"
   set EXTRA = "$COMANS[7]"

   set OK_COLOR   = 229922

   # Set up window for compare results.
   o_tooling
   o FONT $NORM_FNT
   o BG $NORM_COL
   o BW 0
   o LABEL Cad Net Compare Pop-up.
   o LABEL Netlist Comparison Results
   if ($SHORT == 0) then
      o BG $OK_COLOR
   else
      o BG $WARN_COL
   endif		
   o LABEL Shorted = $SHORT
   if ($BROKE == 0) then
      o BG $OK_COLOR
   else
      o BG $WARN_COL
   endif		
   o LABEL Broken = $BROKE
   if ($MISS == 0) then
      o BG $OK_COLOR
   else
      o BG $WARN_COL
   endif		
   o LABEL Missing = $MISS
   if ($EXTRA == 0) then
      o BG $OK_COLOR
   else
      o BG $WARN_COL
   endif		
   o LABEL Extra = $EXTRA
   o BG $NORM_COL
   o LABEL Select netlist page option required
   o RADIO select OPTIONS: V 1 993355
   o Open Netlist Analyser to debug
   o Return to form
   o END

   do_gui

   if ($select == 1) then
      COM netlist_page_open,set=no
      PAUSE Debug netlist, press continue when complete
   	
      # Close netlist.
      COM netlist_page_close
   endif	

   # Set additional log notes.
   set ADD_NOTES = "Run in automatic mode - CAD netlist found"
else
   # Set additional log notes.
   set ADD_NOTES = "Run in automatic mode - No CAD netlist found"
endif

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

set_complete genform1 cnc

save_job

exit 0
