#!/bin/sh
# \
exec oagwish "$0" "$@"

# $Log: not supported by cvs2svn $
# Revision 1.4  1996/03/04 19:55:02  saunders
# Added revision/author to Version menu.
#
# Revision 1.3  1996/01/17  16:58:37  saunders
# Added /usr/local/oag/lib_patch to front to auto_path.
#
# Revision 1.2  1996/01/12  22:36:03  saunders
# Removing dependence on ~borland/tcl/rel auto_path entry. There are still
# references to personal directories. Also fixed minor bugs as encountered.
#
# Revision 1.1  1996/01/02  19:23:50  saunders
# Bringing official area up to date with Christmas 95 commissioning activity.
#

set auto_path [linsert $auto_path 0 /usr/local/oag/apps/lib/$env(HOST_ARCH)]
set auto_path [linsert $auto_path 0  /usr/local/oag/lib_patch/$env(HOST_ARCH)]
set CVSRevisionAuthor "\$Revision: 1.5 $ \$Author: borland $"

set cmlist   {L1:GM1 L1:CM1 L3:CM1 L5:CM1}
set cmvlist  {L1GM1 L1CM1 L3CM1 L5CM1}
set fclist   {L3:FC L5:FC:N L5:FC:S}
set fcvlist  {L3FC L5FCN L5FCS}
set bpmlist  {L1:PM1 L2:PM1 L2:PM2 L2:PM3 L3:PM1 L4:PM1 L4:PM2 L4:PM3 L5:PM2 L5:PM3 L5:PM4 L5:FCN}
set bpmvlist {L1PM1 L2PM1 L2PM2 L2PM3 L3PM1 L4PM1 L4PM2 L4PM3 L5PM2 L5PM3 L5PM4 L5FCNBPM}

# source LDC.tcl

# Set default values for the time increment in ns and average factor

set timeinc 5
set avgfactor 2

APSApplication . -name "APSLinacDiagConfig" -version $CVSRevisionAuthor \
                 -overview "This is an application to perform linac diagnostics timing scans and configuration."

APSStatusLine .status -variable LDCStatus -parent .userFrame -width 60 -packOption {-side top}

APSFrame .tscanframe -parent .userFrame -label "Configure and Execute Timing Scan" -width 50 \
                     -height 30 \
                     -contextHelp "Configure and execute diagnostics timing scans."

APSFrame .setavgframe -parent .userFrame -label "Configure and Set the Average Factor" -width 50 \
                      -height 30 \
                      -contextHelp "Configure and set the diagnostics average factor."

APSLabeledEntry .tinc -parent .userFrame.tscanframe.frame -textVariable timeinc \
                      -packOption {-side left -expand 1} -label "Time increment for scan (ns): " 

APSButton .tscan -parent .userFrame.tscanframe.frame \
          -text "Scan" \
          -command {DoLinacDiagTScanOrSetAvg Scan} \
          -packOption {-side left -expand 1} \
          -contextHelp "Brings up choices and buttons for linac diagnostics timing scans."

APSLabeledEntry .avgf -parent .userFrame.setavgframe.frame -textVariable avgfactor \
                      -packOption {-side left -expand 1} -label "Average factor:              "

APSButton .setavg -parent .userFrame.setavgframe.frame \
          -text "Set" \
          -command {DoLinacDiagTScanOrSetAvg Avg} \
          -packOption {-side left -expand 1} \
          -contextHelp "Brings up choices and buttons to set the linac diagnostics averaging factor."

APSFrame .selectionframe -parent .userFrame -label "Linac Diagnostics Selection Panel" \
                         -packOption {-side top -fill x} \
                         -contextHelp "Selection panel for BPMs, current monitors and faraday cups."

APSFrame .bpmframe -parent .userFrame.selectionframe.frame -label "" \
                   -packOption {-side left -expand 1 -fill x} \
                   -contextHelp "Selection panel for BPMs."

APSFrame .cmfcframe -parent .userFrame.selectionframe.frame -label "" \
                    -packOption {-side left -expand 1 -fill x} \
                    -contextHelp "Selection panel for current monitors and faraday cups."

APSCheckButtonFrame .cmcblist -parent .userFrame.selectionframe.frame.cmfcframe.frame \
                              -label "Current Monitors" -buttonList $cmlist \
                              -variableList "$cmvlist" -allNone 1 \
                              -packOption {-side top -expand 1}
APSCheckButtonFrame .fccblist -parent .userFrame.selectionframe.frame.cmfcframe.frame \
                              -label "Faraday Cups" -buttonList $fclist \
                              -variableList "$fcvlist" -allNone 1 \
                              -packOption {-side top -expand 1}
APSCheckButtonFrame .bpmcblist -parent .userFrame.selectionframe.frame.bpmframe.frame \
                               -label "BPMs" -buttonList $bpmlist \
                               -variableList "$bpmvlist" -allNone 1 \
                               -packOption {-side top -expand 1}

proc SetLDCStatus {text} {
        global LDCStatus
        set LDCStatus $text     
        update
}

proc DoLinacDiagTScanOrSetAvg {action} {
        DisableDiagnosticsButtons
        PerformActionOnSelectedDiagnostics $action -statusCallback SetLDCStatus
        EnableDiagnosticsButtons
        }

proc DisableDiagnosticsButtons {} {
        APSDisableButton .userFrame.tscanframe.frame.tscan.button
        APSDisableButton .userFrame.setavgframe.frame.setavg.button
        }

proc EnableDiagnosticsButtons {} {
        APSEnableButton .userFrame.tscanframe.frame.tscan.button
        APSEnableButton .userFrame.setavgframe.frame.setavg.button
        }
