! 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_feature.mm,v 1.3 2013/03/08 21:06:55 jwb Exp $
!
startmacro l:size[40k]
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE
  switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE

  if interAct then
    set instructions "There should be a red box lined up with the center of the &
                      plot at 0.2 seconds.  Zoom in on the plot (around the box): &
                      the box should still be visible and accurately lined up in &
                      the center (i.e. stretching exactly from 0.18 to 0.22). &
                      Now draw new boxes (both zoomed in and out), confirming &
                      that they stay where they are drawn.  Run this &
                      test with parameters 40K, 400K and 4000K"

    set flag    "/all"

    set format  SF
    set amp     20k
    set ftime   0.2
    calc dtime  ftime 5 /
    calc delta  40k size / 0.01 *

    waveform wavetempbug1878 format size RAMP amp=amp
    headermod wavetempbug1878 fs=1k type=2000 xu=freq yu=time yd=^delta

    pipe init
      panel/msgid=MAIN/setup/controls=gc
      plot/id=idplot/msgid=MAIN/READOUT=Show|OnAxis|X|Y|T|dT^flag wavetempbug1878

      ! 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|FILLED,COLOR=RED,ENABLE=1} plot=idplot

      set box1.x 700
      set box1.t ftime
      set box1.dx 500
      set box1.dt dtime

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

    pipe off
    erase wavetempbug1878
  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.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
    endif
  else
    !say "Unhandled message name=^msg.name info=^msg.info fid=^msg.fid data=^msg.data"
  endif

return
