!******************************************************************************!
! Test case for including arguments with an OPENFILE message
!
! @bug      2710 PLOT: Add ability to pass in arguments to OPENFILE message
! @author:  J Bauer
!******************************************************************************!
startmacro
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE  ! for normal interactive test(s)
  switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE  ! for defects or more obscure test case(s)

  call setDatDir

  if interAct then
    set instructions "You should see a blank plot and a plot of a penny.\n\n&
                      1. Click each button ONLY ONCE and IN ORDER."

    ramp ram:myramp elem=40k
    res file1 "ram:myramp"
    res file2 "^{datDir}.apenny.prm"

    pipe on
      panel/msgid=MAIN/setup/controls=gc
      gcontrol label macro "Test MACRO"
      gcontrol menu  main "Exit with Status =" "PASS,FAIL" TABLE={ItemColors={PASS="GREEN",FAIL="RED"}} /tleft

      gcontrol text  idtext "Instructions" instructions 24 10 /title

      ! Create two plot, one blank and one not blank
      plot/id=plot1
      plot/id=plot2 "^file2"

      gcontrol line

      ! create the buttons to send messages
      gcontrol button updatePlot1 "Update Plot 1" "First,Second"
      gcontrol button updatePlot2 "Update Plot 2" "First,Second,Third"

    pipe off

  endif
endmacro

!******************************************************************************!
! Main process message for this macro. Should be right after the ENDMACRO.
!******************************************************************************!
procedure processMessage m:msg
  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name: User indicated tests" msg.data eqss "PASS"
    pipe stop

  elseif msg.name eqs "UPDATEPLOT1" then
    call update_plot1 msg.data

  elseif msg.name eqs "UPDATEPLOT2" then
   call update_plot2 msg.data

  else
    say "Unhandled message name: ^msg.name from fid: ^msg.fid data: ^msg.data"
  endif
return

!******************************************************************************!
! If an unexpected exception is caught, mark test as failed, unless it is expected
!******************************************************************************!
procedure processException m:emsg
  if expectedException REXISTS then
    assert/text="^reg.main.name: Expected ERROR starts with: ^{expectedException}" expectedException EQSS emsg.data.message
    remove expectedException
  else
    assert/text="^reg.main.name: Caught unexpected exception ^{emsg.data}" "FALSE" isTrue
    if "Trace" SUBS ENV.DEBUG then invoke ,, emsg.data.printStackTrace()
  endif
return

!******************************************************************************!
! Set the dat directory
!******************************************************************************!
procedure setDatDir
  invoke nxmMajor env.nmversion.subString(0,1)
  invoke major java.lang.Integer.valueOf(nxmMajor)
  if major GE 4 then
    invoke s:datDir           nxm.sys.test.DatLocator.getDatDirLocation()
    invoke s:datDirSlash      nxm.sys.test.DatLocator.getDatDirSlashLocation()
    invoke z:sysDatFull       nxm.sys.test.DatLocator.sysDatFull()
    invoke z:sysTestDatExists nxm.sys.test.DatLocator.sysTestDatExists()
  else
    set s:datDir           "nxm.sys.dat"
    set s:datDirSlash      "nxm/sys/dat"
    set z:sysDatFull       true
    set z:sysTestDatExists false
  endif
return

!******************************************************************************!
! Update the first plot
!******************************************************************************!
procedure update_plot1 s:seq
  if seq eqs "FIRST" then
    message send plot1 name="OPENFILE" data="^file1" info=0
    set num 1
  elseif seq EQS "SECOND" then
    message send plot1 name="OPENFILE" data=^file1 info=-1 quals="{/ALL=true}"
    set num 2
  else
    message send plot1 name="OPENFILE" data=^file1 info=-1 quals="{/all=true}"
    set num 3
  endif
  call set_instr num
return

!******************************************************************************!
! Update the second plot
!******************************************************************************!
procedure update_plot2 s:seq
  if seq eqs "FIRST" then
    message send plot2 name="OPENFILE" info=-1 data="^file2" quals="{x1=25,x2=100}"
    set num 4
  elseif seq EQS "SECOND" then
    message send plot2 name="OPENFILE" info=-1 data="^file2" quals="{zmin=25,z2=100}"
    set num 5
  else
    message send plot2 name="OPENFILE" info=-1 data="^file2"
    set num 6
  endif
  call set_instr num
return

procedure set_instr l:buttNum
  if buttNum eq 1 then
    set str "In the top plot, you should see a line plot of a 45 degree ramp.\n\n&
             1. Verify that the top plot can be scrolled horizontally.\n&
             2. Verify that zooming still works after scrolling."
  elseif buttNum eq 2 then
    set str "1. Verify all plot data is shown.\n\n&
             2. Verify that the top plot has NO scrollbar."
  elseif buttNum eq 3 then
    set str "The top plot should change from a straight 45 degrees ramp to 10LOG."
  elseif buttNum eq 4 then
    set str "1. Verify that the bottom plot has x1=25 and x2=100."
  elseif buttNUm eq 5 then
    set str "1. Verify that the bottom plot is a raster form of apenny.\n\n&
                NOTE: Limited Z-range (colors)"
  elseif buttNum eq 6 then
    set str "1. Verify that the bottom plot did not change."
  endif

  set gc.idtext.value "^str"

return
