! Test some of the special features of Layer2D for selecting time boxes in
! a raster plot and handling restarts.
!
! Author:  John Marsh
! Version: $Id: test_plot_layer2d_zooms.mm,v 1.6 2013/03/08 21:13:17 jwb Exp $
! Bug:     2327, others
!
startmacro
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE
  switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE

  if interAct then
    set instructions "Once the pipe has completed (about ten seconds) the display &
                      will show eleven rows alternating red and white, followed &
                      by an orange row. Repeatedly zoom in and then unzoom, &
                      and ensure that the orange row does not get any thicker, &
                      or grow below the 10 second tick mark.  Draw a feature box &
                      by dragging RMB or Shift-LMB, then zoom in and confirm the box is &
                      where you would expect.  While zoomed-in, draw a new feature &
                      then zoom out and confirm the box is where you would expect. &
                      There should not be any Crosshairs artifacts at any time."

    wave  wavef sb 4096 const  0
    wave  jj0   sb 4096 const 60
    merge jj0   wavef
    wave  jj0   sb 4096 const 0
    merge jj0   wavef
    wave  jj0   sb 4096 const 60
    merge jj0   wavef
    wave  jj0   sb 4096 const 0
    merge jj0   wavef
    wave  jj0   sb 4096 const 60
    merge jj0   wavef
    wave  jj0   sb 4096 const 0
    merge jj0   wavef
    wave  jj0   sb 4096 const 60
    merge jj0   wavef
    wave  jj0   sb 4096 const 0
    merge jj0   wavef
    wave  jj0   sb 4096 const 60
    merge jj0   wavef
    wave  jj0   sb 4096 const 0
    merge jj0   wavef
    wave  jj0   sb 4096 const 30
    merge jj0   wavef

    headermod wavef type=2000 xd=9.765625 yd=0.1024 xu=frequency yu=time fs=512 tc="2004:11:29::00:00:00.000000000"

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

      noop/id=wave/rt/tl=4 wavef _waveb
      plot/id=idplot/dblclickzoom/msgid=MAIN/READOUT=Show|OnAxis|T|Y|dT _waveb z1=-60 z2=60 /lpb=16 options=+crosshairs

      ! add box feature to plot for creating a user selectable dragbox on the raster plot
      FEATURE/id=box label=box1 table={NAME=BOX1,TYPE=BOX,COLOR=WHITE,ENABLE=1} plot=idplot

      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 18 /title

      ! The bits below were added for Bug 2327
      invoke isDB reg.idplot.isDoubleBuffered()   ! get state of double-buffering
      if isDB then
        ! do nothing
      else
        invoke reg.idplot.setDoubleBuffered(true)
      endif
    pipe off
  endif

  !BUG 1744
  erase/quiet/warn=n jj0
  erase/quiet/warn=n wavef
endmacro

!******************************************************************************!
procedure processMessage m:msg
  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name: User indicated tests" msg.data eqss "PASS"
    invoke reg.idplot.setDoubleBuffered(isDB)  ! reset double buffering to original
    pipe stop
  elseif msg.fid eqs "IDPLOT"  then
    if msg.name eqs "DRAGBOX" then
      result xmin msg.data.xmin
      result xmax msg.data.xmax
      result tmin msg.data.tmin
      result tmax msg.data.tmax
      calc centerx ^xmin ^xmax + 2 /
      calc centert ^tmin ^tmax + 2 /
      set box1.x ^centerx
      set box1.t ^centert
      calc deltax ^xmax ^xmin -
      calc deltat ^tmax ^tmin -
      set box1.dx ^deltax
      set box1.dt ^deltat
      !invoke ,, box1.refresh()
    endif
  else
    say "Unhandled message name=^msg.name info=^msg.info fid=^msg.fid data=^msg.data"
  endif

return
