! Test opening a zoomed piped Layer2d raster (BUG 51).
!
! Author:  J. Bauer
! Version: $Id: test_plot_bug_51.mm,v 1.2 2013/03/08 20:58:57 jwb Exp $
!
startmacro
  switch INTERACTIVE interAct  GET DEF=TRUE  SDEF=TRUE
  switch BASELINE    baseline  GET DEF=FALSE SDEF=TRUE

  calc sfreq1 1000
  calc sfreq2 4000

  res s:currFile ""

  if interAct then
    set instructions "Click the 'Zoom' button to ZOOM in on the plot. While the plot &
                      is ZOOMed, click the 'Open File' button to replace the file &
                      being plotted. There should not be any drawing irregularities. "

    pipe init
      panel/msgid=MAIN/setup/controls=gc

      waveform/id=wave1/throttle=real _wave1 "SF" Inf sin freq=sfreq1 amp=1e4 delta=1e-4
      waveform/id=wave2/throttle=real _wave2 "SF" Inf sin freq=sfreq2 amp=1e4 delta=1e-4


      fft/dbf _wave1 _waveb{form=sb} nfft=1k over=0
      fft/dbf _wave2 _wavec{form=sb} nfft=1k over=0

      set currFile "_waveb"

      plot/id=idplot/READOUT=Show|OnAxis|T|dT "^currFile" /lpb=16

      gcontrol label  macro   "MACRO"
      gcontrol menu main "Exit with Status = " "PASS,FAIL" /tleft
      set gc.main.itemColors   {PASS=GREEN,FAIL=RED}
      gcontrol text idtext "Instructions" "^instructions" 24 10 /title

      gcontrol button zoomit "" "Zoom" none
      gcontrol button swapit "" "Open File" none

    pipe off

  endif
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 "SWAPIT" then
    call swapFile

  elseif msg.name eqs "ZOOMIT" then
    message send idplot name="ZOOM" data={xmin=1000,xmax=3000,ymin=5,ymax=15}

  else
    say "Unhandled message name=^msg.name info=^msg.info fid=^msg.fid data=^msg.data"
  endif
return

!******************************************************************************!
procedure swapFile
  if currFile eqss "_waveb" then
    set currFile "_wavec"
  else
    set currFile "_waveb"
  endif
  message send idplot name="OPENFILE" info=-1 data="^currFile"
return
