! Test a time-based layer2d file with features and non-standard views
!
! Author: J Bauer
! @version: $Id: test_plot_layer2d_time.mm,v 1.3 2013/03/07 16:15:12 ntn Exp $
!******************************************************************************!
startmacro

  wave ram:junk elem=1k
  headermod ram:junk type=2000 xu=freq xd=1000 yu=time fs=16 yd=16

  set instructions "1. Use the right mouse button or shift+left mouse button &
                    to make a box on the plot. Do the same in different views.\n &
                    2. Move mouse around, the x value's units in the READOUT should be 'kHz'"

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

    ! since 3.3.2: added /XMULT= and +Units in readout to test BUG 2711
    plot/id=idplot/msgid=MAIN/READOUT=+T|+ONAXIS|+Units ram:junk /xmult=K

    ! 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 10 /title

  pipe off

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
      if tmax lt tmin then
        set d:tmp tmin
        set tmin ^tmax
        set tmax ^tmp
      endif
      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
      !timex tmin sod=gc.tmin.value
      !timex tmax sod=gc.tmax.value
    endif
  else
    say "Unhandled message name=^msg.name info=^msg.info fid=^msg.fid data=^msg.data"
  endif

return
