! Tests plotting a Feature on a Type 100 file (BUG 2166)
!
! Author:  J Hallam, J. Bauer
!
startmacro

  set tc   2008:02:28::16:57:09.657
  set init 2008:02:28::16:57:39.657
  
  set instr "Click on each plot with the left mouse button and the blue line should move to the click point. &
             Draw a box on each plot with the right mouse button or shift + left mouse button &
             and a box feature should appear on the plot."

  wave out=ram:ramfile form=SI elem=122 shape=white delta=2
  headermod ramfile tc=^tc

  pipe on

    panel/msgid=main/setup/controls=gc

    plot/all/id=idplot1/msgid=main ramfile view=iXY readout=SHOW|ONAXIS|T
    plot/id=idplot2/msgid=main     ramfile view=iYX readout=SHOW|ONAXIS|T

    new "nxm.sys.libg.Feature" HLFEAT {name="TIMEFEATTOP",type=XLINE,DT=0,t=^init,color=blue,enable=GLOBAL}
    set reg.idplot1.addFeature hlfeat
    new "nxm.sys.libg.Feature" VLFEAT {name="TIMEFEATBOT",type=XLINE,DX=1,X=30,color=blue,enable=GLOBAL}
    set reg.idplot2.addFeature vlfeat
    
    ! add box feature to the plots 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=idplot1
    FEATURE/id=box label=box2 table={NAME=BOX2,TYPE=BOX,COLOR=WHITE,ENABLE=1} plot=idplot2
  
    gcontrol label macro "MACRO"
      gcontrol menu main "Exit with Status = " "PASS,FAIL" /tleft
      set gc.main.itemColors {PASS=GREEN,FAIL=RED}
    gcontrol text info "Instructions" "^instr",,12

  pipe off


endmacro

!******************************************************************!
procedure processMessage m:msg

  if msg.name eqs "MAIN" then
    assert/text="Test Box" msg.data eqss "PASS"
    pipe stop

  elseif msg.name eqs "DRAGBOX" then   
      result xmin msg.data.xmin
      result xmax msg.data.xmax
      result ymin msg.data.ymin
      result ymax msg.data.ymax
      calc centerx ^xmin ^xmax + 2 /
      calc centery ^ymin ^ymax + 2 /
      calc deltax ^xmax ^xmin -
      calc deltay ^ymax ^ymin -
      if msg.fid eqs "IDPLOT1" then
        set box1.x ^centerx
        set box1.y ^centery
        set box1.dx ^deltax
        set box1.dy ^deltay
      elseif msg.fid eqs "IDPLOT2" then
        set box2.x ^centerx
        set box2.y ^centery
        set box2.dx ^deltax
        set box2.dy ^deltay
      endif
  elseif msg.name eqs "MARK" then
    timex ^msg.data.t s:tstr
    if msg.fid eqs "IDPLOT1" then
      set hlfeat.t ^msg.data.t
    elseif msg.fid eqs "IDPLOT2" then
      set vlfeat.x ^msg.data.x
    endif
    
  else 
    !say "Unhandled message ^msg"
  
  endif

return
o